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 Team API #581

Merged
merged 3 commits into from
Feb 27, 2024
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
32 changes: 32 additions & 0 deletions backend/src/API/teamAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ const membersDao = new MembersDao();

export const allTeams = (): Promise<readonly Team[]> => MembersDao.getAllTeams();

/**
* Updates a current team if exists, otherwise creates a new team. Adds the team to the
* subteams or formerSubteams field of any current members or former members, respectively.
* @param team - The Team object used to update team members.
* @returns - A promise that resolves when the update is complete.
*/
const updateTeamMembers = async (team: Team): Promise<void> => {
const teamCopy = { ...team };
teamCopy.uuid = teamCopy.uuid ? teamCopy.uuid : uuidv4();
Expand All @@ -25,6 +31,12 @@ const updateTeamMembers = async (team: Team): Promise<void> => {
await updateFormerMembers(teamCopy, oldTeam);
};

/**
* Updates the subteams field of any new members or removed members of a team.
* @param team - The Team object that will be used to update current members.
* @param oldTeam - The Team object that represents the old team.
* @returns A promise that resolves when the update is complete.
*/
const updateCurrentMembers = async (team: Team, oldTeam: Team): Promise<void> => {
let newMembers: IdolMember[] = [];
let deletedMembers: IdolMember[] = [];
Expand Down Expand Up @@ -59,6 +71,12 @@ const updateCurrentMembers = async (team: Team, oldTeam: Team): Promise<void> =>
);
};

/**
* Updates the formerSubteams field of any new former members or removed former members of a team.
* @param team - The Team object that will be used to update former members.
* @param oldTeam - The Team object that represents the old team.
* @returns A promise that resolves when the update is complete.
*/
const updateFormerMembers = async (team: Team, oldTeam: Team): Promise<void> => {
let newFormerMembers: IdolMember[] = [];
let removedFormerMembers: IdolMember[] = [];
Expand Down Expand Up @@ -92,6 +110,13 @@ const updateFormerMembers = async (team: Team, oldTeam: Team): Promise<void> =>
);
};

/**
* Creates a team by adding the team to the subteam or formerSubteam field of all members or
* past members, respectively.
* @param teamBody - The Team object that will be created.
* @param member - The IdolMember that is requesting to set the team.
* @returns A promise that resolves to the created Team object.
*/
export const setTeam = async (teamBody: Team, member: IdolMember): Promise<Team> => {
const canEdit = await PermissionsManager.canEditTeams(member);
if (!canEdit) {
Expand All @@ -106,6 +131,13 @@ export const setTeam = async (teamBody: Team, member: IdolMember): Promise<Team>
return teamBody;
};

/**
* Deletes a team by removing the team from the subteams or formerSubteams field of all members,
* leaders, and formerMembers of the team.
* @param teamBody - The Team object that will be deleted.
* @param member - The IdolMember that is requesting to delete the team.
* @returns A promise that resolves to the deleted Team object.
*/
export const deleteTeam = async (teamBody: Team, member: IdolMember): Promise<Team> => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in a separate PR, but I think this function should be renamed to clearTeam, since the team document doesn't actually get deleted from the DB. Assuming that is intentional, all we're doing here is removing all members, leaders, and formerMembers from the team.

if (!teamBody.uuid || teamBody.uuid === '') {
throw new BadRequestError("Couldn't delete team with undefined uuid!");
Expand Down
Loading