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:
19
apps/backend/src/modules/student-portal/features/me/route.ts
Normal file
19
apps/backend/src/modules/student-portal/features/me/route.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Hono } from 'hono';
|
||||
import type { BackendEnv } from '@/http/env';
|
||||
import { resultJson } from '@/http/problem-details';
|
||||
import { currentStudent, studentSession } from '../../middleware';
|
||||
import { GetStudentMe, MarkStudentWelcomed } from './use-case';
|
||||
|
||||
const route = new Hono<BackendEnv>();
|
||||
|
||||
route.get('/me', studentSession, async (c) => {
|
||||
const student = currentStudent(c);
|
||||
return resultJson(c, await new GetStudentMe().execute(student.accountId));
|
||||
});
|
||||
|
||||
route.post('/me/welcome', studentSession, async (c) => {
|
||||
const student = currentStudent(c);
|
||||
return resultJson(c, await new MarkStudentWelcomed().execute(student.accountId));
|
||||
});
|
||||
|
||||
export default route;
|
||||
@@ -0,0 +1,72 @@
|
||||
import type { PrismaClient } from '@generated/prisma/client';
|
||||
import type { ProblemDetails, Result, StudentMe } from '@gruperly/shared';
|
||||
import { err, ok } from '@gruperly/shared';
|
||||
import { unauthorizedProblem } from '@/http/problem-details';
|
||||
import prisma from '@/lib/prisma';
|
||||
|
||||
type StudentMeDeps = { db?: Pick<PrismaClient, 'studentAccount'>; now?: Date };
|
||||
|
||||
export class GetStudentMe {
|
||||
constructor(private readonly deps: StudentMeDeps = {}) {}
|
||||
|
||||
async execute(accountId: string): Promise<Result<StudentMe, ProblemDetails>> {
|
||||
const db = this.deps.db ?? prisma;
|
||||
const account = await db.studentAccount.findUnique({
|
||||
where: { id: accountId },
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
recoveryEmail: true,
|
||||
pendingRecoveryEmail: true,
|
||||
welcomedAt: true,
|
||||
_count: { select: { passkeys: true } },
|
||||
attendees: {
|
||||
where: { attendee: { status: { not: 'DROPPED' } } },
|
||||
orderBy: { createdAt: 'asc' },
|
||||
select: {
|
||||
attendee: {
|
||||
select: {
|
||||
id: true,
|
||||
fullName: true,
|
||||
group: { select: { id: true, name: true, owner: { select: { name: true } } } },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
if (!account) return err(unauthorizedProblem('/student-portal/me'));
|
||||
|
||||
return ok({
|
||||
account: {
|
||||
id: account.id,
|
||||
name: account.name,
|
||||
recoveryEmail: account.recoveryEmail,
|
||||
pendingRecoveryEmail: account.pendingRecoveryEmail,
|
||||
hasPasskey: account._count.passkeys > 0,
|
||||
welcomed: account.welcomedAt !== null,
|
||||
},
|
||||
students: account.attendees.map(({ attendee }) => ({
|
||||
attendeeId: attendee.id,
|
||||
fullName: attendee.fullName,
|
||||
groupId: attendee.group.id,
|
||||
groupName: attendee.group.name,
|
||||
teacherName: attendee.group.owner.name,
|
||||
})),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* The welcome screen is shown until the student goes past it once. */
|
||||
export class MarkStudentWelcomed {
|
||||
constructor(private readonly deps: StudentMeDeps = {}) {}
|
||||
|
||||
async execute(accountId: string): Promise<Result<StudentMe, ProblemDetails>> {
|
||||
const db = this.deps.db ?? prisma;
|
||||
await db.studentAccount.updateMany({
|
||||
where: { id: accountId, welcomedAt: null },
|
||||
data: { welcomedAt: this.deps.now ?? new Date() },
|
||||
});
|
||||
return new GetStudentMe({ db }).execute(accountId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user