import type { Prisma } from '@generated/prisma/client'; export type StudentAccessDb = { studentAccountAttendee: Prisma.StudentAccountAttendeeDelegate; }; /* The authorization rule of every student endpoint: only the attendees linked to the session's account. Anything else is a 404 (we don't confirm ids). */ export async function linkedAttendeeIds(db: StudentAccessDb, accountId: string): Promise { const links = await db.studentAccountAttendee.findMany({ // A DROPPED attendee loses access; a PAUSED one keeps it. where: { accountId, attendee: { status: { not: 'DROPPED' } } }, select: { attendeeId: true }, orderBy: { createdAt: 'asc' }, }); return links.map((link) => link.attendeeId); } export type LinkedAttendeeDb = { attendee: Prisma.AttendeeDelegate }; /* One attendee of the session, with what the student screens need from the group. null for an attendee not linked to the account (or DROPPED): routes answer 404, the same as for an id that doesn't exist. */ export async function findLinkedAttendee(db: LinkedAttendeeDb, accountId: string, attendeeId: string) { return db.attendee.findFirst({ where: { id: attendeeId, status: { not: 'DROPPED' }, studentAccounts: { some: { accountId } }, }, select: { id: true, fullName: true, groupId: true, group: { select: { id: true, name: true, days: true, time: true, createdById: true, owner: { select: { name: true, country: true, transferAlias: true, transferHolder: true } }, }, }, }, }); } export type LinkedAttendee = NonNullable>>;