feat: auto-create MemberLunchPick on attendee writes

Adds ensureLunchPickForAttendingMember helper called from confirm,
adminConfirm, and editAttendees attendee-creation paths. No-ops when
the program has no LunchEvent.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt
2026-04-29 02:28:51 +02:00
parent cdb18cc3d1
commit 1a0afd8c6e
3 changed files with 154 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import type { Prisma, PrismaClient } from '@prisma/client'
type PrismaLike = PrismaClient | Prisma.TransactionClient
/**
* Ensure a MemberLunchPick row exists for the given AttendingMember.
* No-ops when the parent program has no LunchEvent.
* Idempotent — safe to call repeatedly.
*/
export async function ensureLunchPickForAttendingMember(
prisma: PrismaLike,
attendingMemberId: string,
): Promise<void> {
const member = await prisma.attendingMember.findUnique({
where: { id: attendingMemberId },
select: {
id: true,
confirmation: { select: { project: { select: { programId: true } } } },
lunchPick: { select: { id: true } },
},
})
if (!member) return
if (member.lunchPick) return
const programId = member.confirmation.project.programId
const lunchEvent = await prisma.lunchEvent.findUnique({
where: { programId },
select: { id: true },
})
if (!lunchEvent) return
await prisma.memberLunchPick.create({
data: { attendingMemberId: member.id },
})
}