Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkin Nits #189

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/services/mentor/mentor-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ mentorRouter.post("/attendance/", strongJwtVerification, async (req: Request, re
{ new: true },
);

return res.status(StatusCode.SuccessOK).send("Success");
return res.status(StatusCode.SuccessOK).send({ success: true, points: pointCoinUpdateValue });
});

export default mentorRouter;
29 changes: 29 additions & 0 deletions src/services/staff/staff-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,44 @@ import { putAsAttendee, putAsStaff } from "../../testTools.js";
import { EventAttendance } from "database/event-db.js";
import { StatusCode } from "status-code-enum";
import Models from "../../database/models.js";
import { RegistrationApplication } from "database/registration-db.js";

const TESTER_EVENT_ATTENDANCE = {
eventId: "some-event",
attendees: [],
} satisfies EventAttendance;

const TESTER_REGISTRATION = {
userId: "some-user",
hasSubmitted: true,
preferredName: "W",
emailAddress: "w@illinois.edu",
location: "Illinois",
degree: "Associates' Degree",
university: "University of Illinois (Chicago)",
major: "Computer Science",
minor: "Computer Science",
gradYear: 2030,
hackEssay1: "yay",
hackEssay2: "yay",
proEssay: "",
hackInterest: ["Attending technical workshops"],
hackOutreach: ["Instagram"],
dietaryRestrictions: ["None"],
resumeFileName: "GitHub cheatsheet.pdf",
isProApplicant: false,
legalName: "Ronakin Kanandani",
considerForGeneral: false,
requestedTravelReimbursement: true,
gender: "Prefer Not To Answer",
race: ["Prefer Not To Answer"],
optionalEssay: "Optional Essay",
} satisfies RegistrationApplication;

// Before each test, initialize database with Event in EventAttendance
beforeEach(async () => {
await Models.EventAttendance.create(TESTER_EVENT_ATTENDANCE);
await Models.RegistrationApplication.create(TESTER_REGISTRATION);
});

describe("PUT /staff/scan-attendee/", () => {
Expand Down
12 changes: 11 additions & 1 deletion src/services/staff/staff-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ staffRouter.post("/attendance/", strongJwtVerification, async (req: Request, res
* @apiErrorExample Example Error Response:
* HTTP/1.1 404 Not Found
* {"error": "EventNotFound"}
* @apiErrorExample Example Error Response:
* HTTP/1.1 424 Failed Dependency
* {"error": "NoRegistrationData"}
*/
staffRouter.put("/scan-attendee/", strongJwtVerification, async (req: Request, res: Response, next: NextFunction) => {
const payload: JwtPayload | undefined = res.locals.payload as JwtPayload;
Expand All @@ -129,7 +132,14 @@ staffRouter.put("/scan-attendee/", strongJwtVerification, async (req: Request, r
return next(result.error);
}

return res.status(StatusCode.SuccessOK).json({ success: true });
const registrationData = await Models.RegistrationApplication.findOne({ userId: userId }).select("dietaryRestrictions");

if (!registrationData) {
return next(new RouterError(StatusCode.ClientErrorFailedDependency, "NoRegistrationData"));
}
const dietaryRestrictions = registrationData["dietaryRestrictions"];

return res.status(StatusCode.SuccessOK).json({ success: true, dietaryRestrictions: dietaryRestrictions });
});

/**
Expand Down
28 changes: 27 additions & 1 deletion src/services/user/user-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { beforeEach, afterEach, describe, expect, it } from "@jest/globals";
import { AUTH_ROLE_TO_ROLES, TESTER, get, getAsAdmin, getAsAttendee, getAsStaff, putAsAttendee } from "../../testTools.js";

import { AttendeeFollowing } from "database/attendee-db.js";
import { EventFollowers, EventAttendance } from "database/event-db.js";
import { EventFollowers, EventAttendance, Event } from "database/event-db.js";
import { StatusCode } from "status-code-enum";
import Config from "../../config.js";
import { AuthInfo } from "../../database/auth-db.js";
Expand Down Expand Up @@ -44,6 +44,31 @@ const TESTER_EVENT_ATTENDANCE = {
attendees: [],
} satisfies EventAttendance;

const TESTER_EVENT = {
eventId: "some-event",
isStaff: false,
name: "Example Name",
description: "Example Description",
startTime: 1707069600,
endTime: 1707069900,
eventType: "WORKSHOP",
locations: [
{
description: "Siebel ",
tags: [],
latitude: 40.113812,
longitude: -88.224937,
},
],
isAsync: false,
mapImageUrl: "",
sponsor: "",
points: 100,
isPrivate: false,
displayOnStaffCheckIn: false,
isPro: false,
} satisfies Event;

// Before each test, initialize database with tester & other users
beforeEach(async () => {
await Models.UserInfo.create(TESTER_USER);
Expand All @@ -52,6 +77,7 @@ beforeEach(async () => {
await Models.EventFollowers.create(TESTER_EVENT_FOLLOWING);
await Models.AttendeeFollowing.create(TESTER_ATTENDEE_FOLLOWING);
await Models.EventAttendance.create(TESTER_EVENT_ATTENDANCE);
await Models.Event.create(TESTER_EVENT);
});

describe("GET /user/qr/", () => {
Expand Down
8 changes: 7 additions & 1 deletion src/services/user/user-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,13 @@ userRouter.put("/scan-event/", strongJwtVerification, async (req: Request, res:
return next(result.error);
}

return res.status(StatusCode.SuccessOK).json({ success: true });
const eventData = await Models.Event.findOne({ eventId: eventId });
if (!eventData) {
return next(new RouterError(StatusCode.ClientErrorFailedDependency, "NonexistantEvent"));
}
const points = eventData["points"];

return res.status(StatusCode.SuccessOK).json({ success: true, points: points });
});

export default userRouter;
Loading