feat: app de alumnos sin contraseña (invitación de un solo uso, avisos de falta y pagos informados)

- 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>
This commit is contained in:
Jose Selesan
2026-10-28 15:39:09 -03:00
parent b99bc4d519
commit 060a4f09e4
146 changed files with 7994 additions and 32 deletions

View File

@@ -0,0 +1,97 @@
import type { PrismaClient } from '@generated/prisma/client';
import type { ProblemDetails, Result, StudentFeeStatus, StudentFeesDto } from '@gruperly/shared';
import { err, ok } from '@gruperly/shared';
import prisma from '@/lib/prisma';
import { startOfDayInTimeZone } from '@/modules/home/lib/scheduler';
import { findLinkedAttendee, studentAttendeeNotFoundProblem, teacherTimeZone } from '../../lib';
type GetStudentFeesDeps = {
db?: Pick<PrismaClient, 'attendee' | 'payment' | 'reportedPayment'>;
now?: Date;
};
const REPORTS_SHOWN = 10;
const REPORT_STATUS = { REPORTED: 'reported', CONFIRMED: 'confirmed', REJECTED: 'rejected' } as const;
/* Unpaid fees of the attendee and their latest reports. A fee inside a report
the teacher hasn't reviewed shows as "reported" (the Payment row itself is
not touched until the teacher confirms). */
export class GetStudentFees {
constructor(private readonly deps: GetStudentFeesDeps = {}) {}
async execute(accountId: string, attendeeId: string): Promise<Result<StudentFeesDto, ProblemDetails>> {
const db = this.deps.db ?? prisma;
const now = this.deps.now ?? new Date();
const attendee = await findLinkedAttendee(db, accountId, attendeeId);
if (!attendee) return err(studentAttendeeNotFoundProblem());
const startOfToday = startOfDayInTimeZone(now, teacherTimeZone(attendee.group.owner.country));
const [payments, reports] = await Promise.all([
db.payment.findMany({
where: { attendeeId, status: { in: ['PENDING', 'OVERDUE'] } },
orderBy: { dueDate: 'asc' },
select: {
id: true,
description: true,
amount: true,
currency: true,
dueDate: true,
status: true,
checkoutUrl: true,
reportedItems: { where: { reportedPayment: { status: 'REPORTED' } }, select: { paymentId: true } },
},
}),
db.reportedPayment.findMany({
where: { attendeeId },
orderBy: { createdAt: 'desc' },
take: REPORTS_SHOWN,
select: {
id: true,
totalAmount: true,
currency: true,
status: true,
createdAt: true,
reviewedAt: true,
rejectionReason: true,
items: { select: { payment: { select: { id: true, description: true, dueDate: true } } } },
},
}),
]);
const { transferAlias, transferHolder } = attendee.group.owner;
return ok({
attendeeId,
fees: payments.map((payment) => {
let status: StudentFeeStatus = 'pending';
if (payment.reportedItems.length > 0) status = 'reported';
else if (payment.status === 'OVERDUE' || payment.dueDate < startOfToday) status = 'overdue';
return {
id: payment.id,
description: payment.description,
amount: payment.amount.toNumber(),
currency: payment.currency,
dueDate: payment.dueDate.toISOString(),
status,
checkoutUrl: payment.checkoutUrl,
};
}),
transfer: transferAlias ? { alias: transferAlias, holder: transferHolder } : null,
reports: reports.map((report) => ({
id: report.id,
totalAmount: report.totalAmount.toNumber(),
currency: report.currency,
status: REPORT_STATUS[report.status],
createdAt: report.createdAt.toISOString(),
reviewedAt: report.reviewedAt?.toISOString() ?? null,
rejectionReason: report.rejectionReason,
fees: report.items.map(({ payment }) => ({
id: payment.id,
description: payment.description,
dueDate: payment.dueDate.toISOString(),
})),
})),
});
}
}