feat: list-confirmations admin query

This commit is contained in:
Matt
2026-04-28 18:20:40 +02:00
parent b1e6eb81eb
commit d1f29a149a
2 changed files with 211 additions and 0 deletions

View File

@@ -55,6 +55,53 @@ export const logisticsRouter = router({
return hotel
}),
/**
* Read-only listing of every FinalistConfirmation in a program, with the
* joined project + attendee count + decline reason. Sorted by status
* priority (PENDING first) then deadline ascending so the most urgent
* decisions surface at the top of the table.
*/
listConfirmations: adminProcedure
.input(z.object({ programId: z.string() }))
.query(async ({ ctx, input }) => {
const rows = await ctx.prisma.finalistConfirmation.findMany({
where: { project: { programId: input.programId } },
include: {
project: {
select: { id: true, title: true, competitionCategory: true, country: true },
},
_count: { select: { attendingMembers: true } },
},
})
const STATUS_PRIORITY: Record<string, number> = {
PENDING: 0,
CONFIRMED: 1,
DECLINED: 2,
EXPIRED: 3,
SUPERSEDED: 4,
}
return rows
.map((r) => ({
id: r.id,
status: r.status,
deadline: r.deadline,
confirmedAt: r.confirmedAt,
declinedAt: r.declinedAt,
declineReason: r.declineReason,
expiredAt: r.expiredAt,
category: r.category,
promotedFromWaitlistEntryId: r.promotedFromWaitlistEntryId,
project: r.project,
attendeeCount: r._count.attendingMembers,
}))
.sort((a, b) => {
const sa = STATUS_PRIORITY[a.status] ?? 9
const sb = STATUS_PRIORITY[b.status] ?? 9
if (sa !== sb) return sa - sb
return a.deadline.getTime() - b.deadline.getTime()
})
}),
/**
* List all attending members for CONFIRMED finalists in a program, with
* their (optional) flight details. One row per attendee — even those