Skip to content

Commit

Permalink
Merge pull request #60 from HackDavis/feat/team-grouping
Browse files Browse the repository at this point in the history
Updated team API validation
  • Loading branch information
brandonw504 authored Apr 18, 2024
2 parents f428c14 + 8fe9693 commit ccaaac9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/(api)/_data/tracks.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "Best Hack for Social Good",
"weights": [0.5, 0.1, 0.1, 0.2, 0.1],
"type": "general"
"type": "all"
},
{
"name": "Best Beginner Hack",
Expand Down
9 changes: 8 additions & 1 deletion app/(api)/_datalib/teams/createTeams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ export const createTeams = async (body: object[]) => {
const parsedBody = await parseAndReplace(body);

parsedBody.forEach((team: Team) => {
const seenTracks = new Set();
team.tracks.forEach((chosenTrack) => {
const foundTrack = tracks.find((track) => track.name === chosenTrack);
if (foundTrack == undefined) {
throw new BadRequestError('Invalid track');
} else if (seenTracks.has(foundTrack.name)) {
throw new BadRequestError('Duplicate track');
} else if (foundTrack.name === 'Best Hack for Social Good') {
throw new BadRequestError(
'Invalid track: Best Hack for Social Good should not be included'
'Remove default track: Best Hack for Social Good'
);
}
seenTracks.add(chosenTrack);
});

// automatically add Best Hack for Social Good
team.tracks.push('Best Hack for Social Good');
});

const db = await getDatabase();
Expand Down
2 changes: 1 addition & 1 deletion app/(api)/_schema/Team.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const Team = {
},
tracks: {
bsonType: 'array',
maxItems: 3,
maxItems: 4,
items: {
enum: tracks.map((track) => track.name),
description: 'track must be one of the valid tracks',
Expand Down
1 change: 0 additions & 1 deletion app/(api)/_utils/scoring/calculateScore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function calculateScore(
scores: number[],
correlations: Correlation[]
) {
chosenTracks.push('Best Hack for Social Good');
const finalScores = chosenTracks.map((chosenTrack) => {
const weights = tracks.find((track) => track.name == chosenTrack);
const score = weights?.weights.reduce((sum, weight, i) => {
Expand Down

0 comments on commit ccaaac9

Please sign in to comment.