Skip to content

Commit b0d31e1

Browse files
committed
Make admin attendance work
1 parent 3077ca6 commit b0d31e1

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/core/src/modules/attendance/attendee-service.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type { AttendeeRepository } from "./attendee-repository"
2626

2727
export interface AttendeeService {
2828
registerForEvent(userId: string, attendanceId: string, attendancePoolId: string): Promise<Attendee>
29+
adminRegisterForEvent(userId: string, attendanceId: string, attendancePoolId: string): Promise<Attendee>
2930
deregisterForEvent(userId: string, attendanceId: string): Promise<void>
3031
adminDeregisterForEvent(id: AttendeeId): Promise<void>
3132
updateSelectionResponses(id: AttendanceId, responses: AttendanceSelectionResponse[]): Promise<Attendee>
@@ -102,6 +103,32 @@ export class AttendeeServiceImpl implements AttendeeService {
102103
return attendee
103104
}
104105

106+
async adminRegisterForEvent(userId: UserId, attendanceId: AttendancePoolId, attendancePoolId: AttendanceId) {
107+
const user = await this.userService.getById(userId)
108+
const attendance = await this.attendanceRepository.getById(attendanceId)
109+
const attendancePool = attendance.pools.find((pool) => pool.id === attendancePoolId)
110+
111+
if (attendancePool === undefined) {
112+
throw new AttendancePoolNotFoundError("Tried to register to unknown attendance pool")
113+
}
114+
115+
const registerTime = new Date()
116+
117+
const attendee = await this.attendeeRepository.create({
118+
userId,
119+
attendancePoolId,
120+
attendanceId: attendancePool.attendanceId,
121+
122+
displayName: (user.firstName && user.lastName) ?? user.email,
123+
userGrade: user.membership ? getMembershipGrade(user.membership) : null,
124+
125+
reserveTime: registerTime,
126+
reserved: true,
127+
})
128+
129+
return attendee
130+
}
131+
105132
async registerForEvent(userId: UserId, attendanceId: AttendancePoolId, attendancePoolId: AttendanceId) {
106133
const user = await this.userService.getById(userId)
107134
const attendance = await this.attendanceRepository.getById(attendanceId)

packages/gateway-trpc/src/modules/event/attendance-router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const attendanceRouter = t.router({
4949
})
5050
)
5151
.mutation(async ({ input, ctx }) =>
52-
ctx.attendeeService.registerForEvent(input.userId, input.attendanceId, input.attendancePoolId)
52+
ctx.attendeeService.adminRegisterForEvent(input.userId, input.attendanceId, input.attendancePoolId)
5353
),
5454

5555
registerForEvent: protectedProcedure

0 commit comments

Comments
 (0)