- Acceso del alumno o tutor con link de un solo uso (hash SHA-256, consumo atómico, el GET no consume), sesión propia de 90 días deslizante, passkeys opcionales (SimpleWebAuthn) y mail de recuperación con rate limit. - Lado alumno (/i/:token, /acceso, /alumno/*): inicio, clases, avisar falta, pagos, informar pago con comprobante (S3 privado, magic bytes) y perfil. - Lado profe: acceso a la app en la ficha del alumno (invitar/reinvitar), "Pagos para verificar" en Cobros con badge, faltas avisadas en la ficha de grupo y datos para transferir en Ajustes. - "Requiere atención" y el recordatorio de WhatsApp excluyen cuotas informadas. - Zona horaria por defecto: Buenos Aires. - Migración add_student_access, tests contra Postgres real (test:db) y docs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
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<string[]> {
|
|
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<Awaited<ReturnType<typeof findLinkedAttendee>>>;
|