Skip to content

Commit 6a60474

Browse files
feat: properly handle different statues for scanning endpoint (#418)
* fix: check for appropriate status * fix: explicit role handling * Update src/server/router/scanner.ts Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix: coerece type to prevent ts error * fix: use switch for cleaner code --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
1 parent f13508e commit 6a60474

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

src/server/router/scanner.ts

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,41 @@ export const scannerRouter = router({
163163
});
164164
}
165165

166-
if (user.DH12Application.status !== Status.RSVP) {
167-
throw new TRPCError({
168-
code: "UNAUTHORIZED",
169-
message: "User was not accepted to the event",
170-
});
171-
}
172-
173-
// Handle checkIn station separately (no station record needed)
174166
if (stationId === "checkIn") {
175-
await ctx.prisma.dH12Application.update({
176-
where: { id: user.DH12Application.id },
177-
data: { status: Status.CHECKED_IN },
178-
});
167+
// This code is intentionally explicit so it's easy to trace what happens to each status
168+
switch (user.DH12Application.status) {
169+
case Status.IN_REVIEW:
170+
case Status.REJECTED:
171+
case Status.WAITLISTED:
172+
case Status.ACCEPTED: // This might look confusing but a user who didn't RSVP is also considered no accepted
173+
throw new TRPCError({
174+
code: "UNAUTHORIZED",
175+
message: "User was not accepted to the event",
176+
});
177+
case Status.CHECKED_IN:
178+
throw new TRPCError({
179+
code: "CONFLICT",
180+
message: "User is already checked in",
181+
});
182+
case Status.RSVP:
183+
await ctx.prisma.dH12Application.update({
184+
where: { id: user.DH12Application.id },
185+
data: { status: Status.CHECKED_IN },
186+
});
187+
break;
188+
default:
189+
throw new TRPCError({
190+
code: "INTERNAL_SERVER_ERROR",
191+
message: "Unknown status, unable to process check-in",
192+
});
193+
}
179194
} else {
180-
// For food/events, get the station and create event log
195+
if (user.DH12Application.status !== Status.CHECKED_IN) {
196+
throw new TRPCError({
197+
code: "UNAUTHORIZED",
198+
message: "User is not checked in",
199+
});
200+
}
181201
const station = await ctx.prisma.station.findUnique({
182202
where: { id: stationId },
183203
});
@@ -219,7 +239,10 @@ export const scannerRouter = router({
219239

220240
const userInfo = {
221241
id: user.id,
222-
name: user.name,
242+
name:
243+
user.DH12Application?.firstName +
244+
" " +
245+
user.DH12Application?.lastName,
223246
email: user.email,
224247
};
225248
return userInfo;

0 commit comments

Comments
 (0)