Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add documentation to TeamEventsDao #511

Merged
merged 3 commits into from
Sep 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions backend/src/dao/TeamEventsDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { teamEventsCollection, bucket } from '../firebase';
import { NotFoundError } from '../utils/errors';

export default class TeamEventsDao {
/* Gets all TeamEventInfo objects which represent the details of all team events */
static async getAllTeamEvents(): Promise<TeamEventInfo[]> {
const eventRefs = await teamEventsCollection.get();
return Promise.all(eventRefs.docs.map(async (eventRef) => eventRef.data()));
}

/**
* Gets the team event information
* @param uuid - unique identifer corresponding to a team event
* If team event is not found, throw a 'Not Found Error'
*/
static async getTeamEvent(uuid: string): Promise<TeamEventInfo> {
const eventDoc = teamEventsCollection.doc(uuid);
const eventRef = await eventDoc.get();
Expand All @@ -18,13 +24,22 @@ export default class TeamEventsDao {
return eventForm;
}

/**
* Deletes a team event
* @param teamEvent - team event that is to be deleted
* If team event does not exist, throw a 'Not Found Error'
*/
static async deleteTeamEvent(teamEvent: TeamEventInfo): Promise<void> {
const eventDoc = teamEventsCollection.doc(teamEvent.uuid);
const eventRef = await eventDoc.get();
if (!eventRef.exists) throw new NotFoundError(`No team event '${teamEvent.uuid}' exists.`);
await eventDoc.delete();
}

/**
* Creates a team event
* @param event - newly created TeamEventInfo object that represent the details of the event
*/
static async createTeamEvent(event: TeamEventInfo): Promise<TeamEventInfo> {
const teamEventRef: TeamEventInfo = {
...event,
Expand All @@ -35,6 +50,11 @@ export default class TeamEventsDao {
return event;
}

/**
* Updates a team event
* @param event - team event that is to be updated
* If team event does not exist, throw a 'Not Found Error'
*/
static async updateTeamEvent(event: TeamEventInfo): Promise<TeamEventInfo> {
const eventDoc = teamEventsCollection.doc(event.uuid);
const eventRef = await eventDoc.get();
Expand All @@ -56,6 +76,7 @@ export default class TeamEventsDao {
await Promise.all(proofImageFiles[0].map((file) => file.delete()));
}

/* Returns all team event information details through 'TeamEventInfo' objects */
static async getAllTeamEventInfo(): Promise<TeamEventInfo[]> {
const docRefs = await teamEventsCollection
.select('name', 'date', 'numCredits', 'hasHours', 'uuid')
Expand Down
Loading