Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aydan Pirani committed Sep 18, 2024
1 parent 1d69356 commit b425df7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
14 changes: 11 additions & 3 deletions src/services/checkin/checkin-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ checkinRouter.post(
RoleChecker([Role.Enum.ADMIN, Role.Enum.STAFF]),
async (req, res, next) => {
try {
const { eventId, userId, isCheckin } = EventValidator.parse(
const { eventId, userId } = EventValidator.parse(

Check failure on line 54 in src/services/checkin/checkin-router.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎················req.body⏎············` with `req.body`
req.body
);

await checkInUserToEvent(eventId, userId, isCheckin);

try {
await checkInUserToEvent(eventId, userId);
} catch (error: unknown) {
if (error instanceof Error && error.message == "IsDuplicate") {
return res
.status(StatusCodes.FORBIDDEN)
.json({ error: "IsDuplicate" });
}
return res.sendStatus(StatusCodes.INTERNAL_SERVER_ERROR);
}
return res.status(StatusCodes.OK).json(userId);
} catch (error) {
next(error);
Expand Down
1 change: 0 additions & 1 deletion src/services/checkin/checkin-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ const MerchScanValidator = z.object({
const EventValidator = z.object({
eventId: z.string(),
userId: z.string(),
isCheckin: z.boolean(),
});

export { ScanValidator, MerchScanValidator, EventValidator };
25 changes: 19 additions & 6 deletions src/services/checkin/checkin-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Database } from "../../database";
import crypto from "crypto";
import { Config } from "../../config";
import { EventType } from "../events/events-schema";

export function getCurrentDay() {
const currDate = new Date();
Expand Down Expand Up @@ -47,6 +48,7 @@ async function updateAttendeePriority(userId: string) {
);
}


Check failure on line 51 in src/services/checkin/checkin-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
async function updateAttendanceRecords(eventId: string, userId: string) {
await Promise.all([
Database.EVENTS_ATTENDANCE.findOneAndUpdate(
Expand Down Expand Up @@ -83,24 +85,35 @@ async function assignPixelsToUser(userId: string, pixels: number) {
);
}

async function markUserAsCheckedIn(userId: string) {
await Database.ATTENDEE.findOneAndUpdate(
{ userId },
{ $set: { hasCheckedIn: true } }
);
}

export async function checkInUserToEvent(

Check failure on line 95 in src/services/checkin/checkin-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····eventId:·string,⏎····userId:·string,⏎` with `eventId:·string,·userId:·string`
eventId: string,
userId: string,
isCheckin: boolean = false
) {
await checkEventAndAttendeeExist(eventId, userId);
await checkForDuplicateAttendance(eventId, userId);

Check failure on line 101 in src/services/checkin/checkin-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
const event = await Database.EVENTS.findOne({ eventId });
if (!event) {
throw new Error("Event not found");
}

if (!isCheckin) {
// check for checkin event, and for meals
if (event.eventType == EventType.Enum.CHECKIN) {
await markUserAsCheckedIn(userId);
} else if (event.eventType != EventType.Enum.MEALS){

Check failure on line 110 in src/services/checkin/checkin-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `·`
await updateAttendeePriority(userId);
}

await updateAttendanceRecords(eventId, userId);

Check failure on line 114 in src/services/checkin/checkin-utils.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

const event = await Database.EVENTS.findOne({ eventId });
if (!event) {
throw new Error("Event not found");
}

await assignPixelsToUser(userId, event.points);
}

Expand Down
1 change: 1 addition & 0 deletions src/services/events/events-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const EventType = z.enum([
"SPECIAL",
"PARTNERS",
"MEALS",
"CHECKIN",
]);

export const externalEventView = z.object({
Expand Down

0 comments on commit b425df7

Please sign in to comment.