Skip to content

Commit

Permalink
merch endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
riyap committed Sep 5, 2024
1 parent 1485bbf commit fb49b1a
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
50 changes: 50 additions & 0 deletions src/services/attendee/attendee-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,56 @@ attendeeRouter.get(
}
);

attendeeRouter.post(
"/redeemMerch/:ITEM",
RoleChecker([]),
async (req, res, next) => {
try {
const payload = res.locals.payload;
const userId = payload.userId;
const merchItem = req.params.ITEM

Check failure on line 189 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `;`

// Check if the user exists in the database
const user = await Database.ATTENDEE.findOne({ userId });

if (!user) {
return res
.status(StatusCodes.NOT_FOUND)
.json({ error: "UserNotFound" });
}

if (merchItem == "Cap" || merchItem == "Tote" || merchItem == "Button") {

Check failure on line 200 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `merchItem·==·"Cap"·||·merchItem·==·"Tote"·||·merchItem·==·"Button"` with `⏎················merchItem·==·"Cap"·||⏎················merchItem·==·"Tote"·||⏎················merchItem·==·"Button"⏎············`
if (!(user.isEligibleMerch![merchItem])) {

Check failure on line 201 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `(user.isEligibleMerch![merchItem]))` with `user.isEligibleMerch![merchItem])`
return res.status(StatusCodes.BAD_REQUEST).json({ error: "Too few points" });

Check failure on line 202 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `.status(StatusCodes.BAD_REQUEST)` with `⏎························.status(StatusCodes.BAD_REQUEST)⏎························`
}

Check failure on line 203 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎⏎················else·if·((user.hasRedeemedMerch![merchItem])` with `else·if·(user.hasRedeemedMerch![merchItem]`

else if ((user.hasRedeemedMerch![merchItem])) {
return res.status(StatusCodes.BAD_REQUEST).json({ error: "Item already redeemed" });

Check failure on line 206 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `.status(StatusCodes.BAD_REQUEST)` with `⏎························.status(StatusCodes.BAD_REQUEST)⏎························`
}

Check failure on line 207 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎⏎···············`

else {
await Database.ATTENDEE.updateOne(
{ userId },
{ $set: { [`hasRedeemedMerch.${merchItem}`]: true } }
);

return res.status(StatusCodes.OK).json({ message: "Item Redeemed!" });

Check failure on line 215 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `.status(StatusCodes.OK)` with `⏎························.status(StatusCodes.OK)⏎························`
}
}

Check failure on line 217 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎⏎···········`

else {
return res.status(StatusCodes.BAD_REQUEST).json({ error: "Not a valid item" });

Check failure on line 220 in src/services/attendee/attendee-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `.status(StatusCodes.BAD_REQUEST)` with `⏎····················.status(StatusCodes.BAD_REQUEST)⏎····················`
}

} catch (error) {
next(error);
}
}
);




attendeeRouter.get("/resume/update/:ENCODED_ID", async (req, res) => {
const ENCODED_ID = req.params.ENCODED_ID;
const decrypted_id = await decryptId(ENCODED_ID);
Expand Down
21 changes: 21 additions & 0 deletions src/services/attendee/attendee-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ export const AttendeeSchema = new Schema({
Sun: false,
},
},
hasRedeemedMerch: {
type: new Schema(
{
Button: { type: Boolean, default: false },
Tote: { type: Boolean, default: false },
Cap: { type: Boolean, default: false },
},
{ _id: false }
),
},
isEligibleMerch: {
type: new Schema(
{
Button: { type: Boolean, default: false },
Tote: { type: Boolean, default: false },
Cap: { type: Boolean, default: false },
},
{ _id: false }
),
},

favorites: [{ type: String }],
puzzlesCompleted: [{ type: String, default: [] }],
});
Expand Down
19 changes: 17 additions & 2 deletions src/services/checkin/checkin-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,25 @@ async function updateAttendanceRecords(eventId: string, userId: string) {
]);
}

async function assignPixelsToUser(userId: string, pixels: number) {
export async function assignPixelsToUser(userId: string, pixels: number) {
const updatedDoc = await Database.ATTENDEE.findOneAndUpdate(
{ userId },
{ $inc: { points: pixels } },
{ new: true }
);
console.log("here")

const new_points = updatedDoc!.points;
const updatedFields = {
'isEligibleMerch.Cap': new_points >= 50,
'isEligibleMerch.Tote': new_points >= 35,
'isEligibleMerch.Button': new_points >= 20
};
console.log(updatedFields)

await Database.ATTENDEE.findOneAndUpdate(
{ userId },
{ $inc: { points: pixels } }
{ $set: updatedFields }
);
}

Expand Down

0 comments on commit fb49b1a

Please sign in to comment.