-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #115 from ReflectionsProjections/dev/aydan/puzzlebang
Refactor API + PuzzleBang Changes
- Loading branch information
Showing
11 changed files
with
90 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { z } from "zod"; | ||
|
||
// Zod schema for attendee | ||
export const AttendeeCreateValidator = z.object({ | ||
userId: z.string(), | ||
name: z.string(), | ||
email: z.string().email(), | ||
dietaryRestrictions: z.string().array(), | ||
allergies: z.string().array(), | ||
}); | ||
|
||
export const EventIdValidator = z.object({ | ||
eventId: z.string().uuid(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Router } from "express"; | ||
import { StatusCodes } from "http-status-codes"; | ||
import { Database } from "../../database"; | ||
import RoleChecker from "../../middleware/role-checker"; | ||
import { Role } from "../auth/auth-models"; | ||
import { PuzzlebangCompleteRequestValidator } from "./puzzlebang-validators"; | ||
|
||
const puzzlebangRouter = Router(); | ||
|
||
puzzlebangRouter.post( | ||
"/", | ||
RoleChecker([Role.Enum.PUZZLEBANG]), | ||
async (req, res, next) => { | ||
try { | ||
const requestInfo = PuzzlebangCompleteRequestValidator.parse( | ||
req.body | ||
); | ||
|
||
const attendeeData = await Database.ATTENDEE.findOneAndUpdate( | ||
{ email: requestInfo.email }, | ||
{ $addToSet: { puzzlesCompleted: requestInfo.puzzleId } }, | ||
{ new: false } | ||
); | ||
|
||
if (!attendeeData) { | ||
return res.sendStatus(StatusCodes.NOT_FOUND); | ||
} | ||
|
||
if (attendeeData.puzzlesCompleted.includes(requestInfo.puzzleId)) { | ||
return res.sendStatus(StatusCodes.UNAUTHORIZED); | ||
} | ||
|
||
return res.sendStatus(StatusCodes.OK); | ||
} catch (error) { | ||
next(error); | ||
} | ||
} | ||
); | ||
|
||
export default puzzlebangRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { z } from "zod"; | ||
|
||
export const PuzzlebangCompleteRequestValidator = z.object({ | ||
// userId: z.string(), | ||
email: z.string().email(), | ||
puzzleId: z.string(), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters