Skip to content

Commit

Permalink
add documentation to TeamEventsDao (#511)
Browse files Browse the repository at this point in the history
* add documentation to TeamEventsDao

* run prettier

* fix typos
  • Loading branch information
alyssayzhang authored Sep 29, 2023
1 parent 21911b5 commit 3aa47f9
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 3aa47f9

Please sign in to comment.