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

@@ -52,6 +52,23 @@ import type {
PaymentList,
PaymentQuery,
ProblemDetails,
StudentLinkInfo,
ConsumeStudentLinkResult,
StudentMe,
PasskeyOptionsResult,
PasskeyVerify,
StudentClassesDto,
CreateAbsenceNotices,
CreateAbsenceNoticesResult,
StudentFeesDto,
StudentAccessDto,
StudentInvitationDto,
ReportedPaymentList,
ReportedPaymentDto,
ReceiptUrlDto,
TransferDetailsDto,
UpdateTransferDetails,
TeacherAbsenceNoticeList,
PromoteGroupWaitlistEntryResult,
PublicNotifyAbsence,
RejectGroupPreRegistrationResult,
@@ -92,7 +109,8 @@ type JsonBody = Record<string, unknown> | unknown[]
async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
const headers = new Headers(init?.headers)
headers.set('Content-Type', 'application/json')
// A FormData body sets its own multipart Content-Type (with the boundary).
if (!(init?.body instanceof FormData)) headers.set('Content-Type', 'application/json')
const res = await fetch(`${API_URL}${path}`, {
...init,
@@ -113,6 +131,7 @@ async function apiFetch<T>(path: string, init?: RequestInit): Promise<T> {
throw new ApiError(res.status, problem)
}
if (res.status === 204) return undefined as T
return (await res.json()) as T
}
@@ -412,3 +431,126 @@ export const getAdminAccounts = (params: AdminAccountQueryInput) => {
export const getAdminAccount = (accountId: string) =>
apiFetch<AdminAccountDetail>(`/api/v1/admin/accounts/${encodeURIComponent(accountId)}`)
// — App del alumno (sesión propia, nunca la del profe) —
const STUDENT_API = '/api/v1/student-portal'
export const getStudentLinkInfo = (token: string) =>
apiFetch<StudentLinkInfo>(`${STUDENT_API}/links/${encodeURIComponent(token)}`)
export const consumeStudentLink = (token: string) =>
apiFetch<ConsumeStudentLinkResult>(`${STUDENT_API}/links/${encodeURIComponent(token)}/consume`, {
method: 'POST',
})
export const getStudentMe = () => apiFetch<StudentMe>(`${STUDENT_API}/me`)
export const markStudentWelcomed = () => apiFetch<StudentMe>(`${STUDENT_API}/me/welcome`, { method: 'POST' })
export const logoutStudent = () => apiFetch<void>(`${STUDENT_API}/logout`, { method: 'POST' })
export const setStudentRecoveryEmail = (email: string) =>
apiFetch<StudentMe>(`${STUDENT_API}/me/recovery-email`, {
method: 'PUT',
body: JSON.stringify({ email }),
})
export const removeStudentRecoveryEmail = () =>
apiFetch<StudentMe>(`${STUDENT_API}/me/recovery-email`, { method: 'DELETE' })
export const confirmStudentRecoveryEmail = (token: string) =>
apiFetch<{ email: string }>(`${STUDENT_API}/recovery-email/confirm`, {
method: 'POST',
body: JSON.stringify({ token }),
})
export const requestStudentRecoveryLink = (email: string) =>
apiFetch<{ accepted: true }>(`${STUDENT_API}/recovery`, {
method: 'POST',
body: JSON.stringify({ email }),
})
export const getStudentPasskeyRegistrationOptions = () =>
apiFetch<PasskeyOptionsResult>(`${STUDENT_API}/passkeys/register/options`, { method: 'POST' })
export const verifyStudentPasskeyRegistration = (payload: PasskeyVerify) =>
apiFetch<StudentMe>(`${STUDENT_API}/passkeys/register/verify`, {
method: 'POST',
body: JSON.stringify(payload),
})
export const removeStudentPasskeys = () =>
apiFetch<StudentMe>(`${STUDENT_API}/passkeys`, { method: 'DELETE' })
export const getStudentPasskeyLoginOptions = () =>
apiFetch<PasskeyOptionsResult>(`${STUDENT_API}/passkeys/login/options`, { method: 'POST' })
export const verifyStudentPasskeyLogin = (payload: PasskeyVerify) =>
apiFetch<ConsumeStudentLinkResult>(`${STUDENT_API}/passkeys/login/verify`, {
method: 'POST',
body: JSON.stringify(payload),
})
export const getStudentClasses = (attendeeId: string) =>
apiFetch<StudentClassesDto>(`${STUDENT_API}/classes?attendeeId=${encodeURIComponent(attendeeId)}`)
export const notifyStudentAbsences = (payload: CreateAbsenceNotices) =>
apiFetch<CreateAbsenceNoticesResult>(`${STUDENT_API}/absences`, {
method: 'POST',
body: JSON.stringify(payload),
})
export const cancelStudentAbsence = (noticeId: string) =>
apiFetch<{ id: string }>(`${STUDENT_API}/absences/${encodeURIComponent(noticeId)}`, { method: 'DELETE' })
export const getStudentFees = (attendeeId: string) =>
apiFetch<StudentFeesDto>(`${STUDENT_API}/fees?attendeeId=${encodeURIComponent(attendeeId)}`)
export const reportStudentPayment = (payload: { attendeeId: string; paymentIds: string[]; file: File }) => {
const form = new FormData()
form.set('attendeeId', payload.attendeeId)
for (const id of payload.paymentIds) form.append('paymentIds', id)
form.set('file', payload.file)
return apiFetch<{ id: string }>(`${STUDENT_API}/payment-reports`, { method: 'POST', body: form })
}
// — Acceso de alumnos a la app (lado profe) —
export const getStudentAccess = (groupId: string, attendeeId: string) =>
apiFetch<StudentAccessDto>(`/api/v1/groups/${groupId}/attendees/${attendeeId}/student-access`)
/* Invitar o reinvitar: revoca el acceso anterior y devuelve el link nuevo (una
sola vez: el backend guarda solo su hash). */
export const inviteStudent = (groupId: string, attendeeId: string) =>
apiFetch<StudentInvitationDto>(`/api/v1/groups/${groupId}/attendees/${attendeeId}/student-access/invite`, {
method: 'POST',
})
export const getGroupAbsenceNotices = (groupId: string) =>
apiFetch<TeacherAbsenceNoticeList>(`/api/v1/groups/${groupId}/absence-notices`)
export const getReportedPayments = () => apiFetch<ReportedPaymentList>('/api/v1/payments/reported')
export const getReceiptUrl = (reportId: string) =>
apiFetch<ReceiptUrlDto>(`/api/v1/payments/reported/${reportId}/receipt`)
export const confirmReportedPayment = (reportId: string) =>
apiFetch<ReportedPaymentDto>(`/api/v1/payments/reported/${reportId}/confirm`, { method: 'POST' })
export const rejectReportedPayment = (reportId: string, reason: string | null) =>
apiFetch<ReportedPaymentDto>(`/api/v1/payments/reported/${reportId}/reject`, {
method: 'POST',
body: JSON.stringify({ reason }),
})
export const undoPaymentReview = (reportId: string) =>
apiFetch<ReportedPaymentDto>(`/api/v1/payments/reported/${reportId}/undo`, { method: 'POST' })
export const getTransferDetails = () => apiFetch<TransferDetailsDto>('/api/v1/payments/transfer-details')
export const updateTransferDetails = (payload: UpdateTransferDetails) =>
apiFetch<TransferDetailsDto>('/api/v1/payments/transfer-details', {
method: 'PUT',
body: JSON.stringify(payload),
})