Skip to content
Open
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
12 changes: 12 additions & 0 deletions backend/src/API/teamEventsAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ export const createTeamEvent = async (
const canCreateTeamEvent = await PermissionsManager.canEditTeamEvent(user);
if (!canCreateTeamEvent)
throw new PermissionError(`User with email ${user.email} cannot create team events`);
if (Number(teamEventInfo.numCredits) > Number(teamEventInfo.maxCredits))
throw new BadRequestError('The maximum credits cannot be greater than the team event credit!');
if (Number(teamEventInfo.maxCredits) % Number(teamEventInfo.numCredits) !== 0)
throw new BadRequestError(
'The maximum credits needs to be a multiple of the team event credit!'
);
Comment on lines +51 to +56
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

could be nice to pull out a shared helper for this between this func and updateTeamEvent

await TeamEventsDao.createTeamEvent(teamEventInfo);
return teamEventInfo;
};
Expand Down Expand Up @@ -92,6 +98,12 @@ export const updateTeamEvent = async (
`User with email ${user.email} does not have permissions to update team events`
);
}
if (Number(teamEventInfo.numCredits) > Number(teamEventInfo.maxCredits))
throw new BadRequestError('The maximum credits cannot be greater than the team event credit!');
if (Number(teamEventInfo.maxCredits) % Number(teamEventInfo.numCredits) !== 0)
throw new BadRequestError(
'The maximum credits needs to be a multiple of the team event credit!'
);
const updatedTeamEvent = await TeamEventsDao.updateTeamEvent(teamEventInfo);
return updatedTeamEvent;
};
Expand Down