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

@@ -1,6 +1,6 @@
import type { WeekDay } from '@gruperly/shared';
export const DEFAULT_TIME_ZONE = process.env.APP_TIMEZONE ?? 'America/Mexico_City';
export const DEFAULT_TIME_ZONE = process.env.APP_TIMEZONE ?? 'America/Argentina/Buenos_Aires';
// Window (in hours) during which an already started class shows as "in progress".
export const CLASS_WINDOW_HOURS = 2;
@@ -185,4 +185,50 @@ export function todayOccurrence(opt: {
export function startOfDayInTimeZone(now: Date, timeZone: string): Date {
const { year, month, day } = wallDateInTimeZone(now, timeZone);
return zonedWallClockToUtc(`${year}-${pad(month)}-${pad(day)}T00:00`, timeZone);
}
}
// Every class start of a group within [from, to), in `timeZone`. Empty when the
// group has no valid schedule.
export function occurrencesBetween(opt: {
days: WeekDay[];
time: string | null;
from: Date;
to: Date;
timeZone: string;
}): Date[] {
const { days, time, from, to, timeZone } = opt;
if (days.length === 0 || !time) return [];
const [hour, minute] = time.split(':').map(Number);
if (
Number.isNaN(hour) ||
Number.isNaN(minute) ||
hour < 0 ||
hour > 23 ||
minute < 0 ||
minute > 59
) {
return [];
}
const dowSet = new Set(days.map((day) => WEEKDAY_TO_DOW[day]));
const { year, month, day } = wallDateInTimeZone(from, timeZone);
const result: Date[] = [];
// One extra day on each side covers the time zone offset.
const spanDays = Math.ceil((to.getTime() - from.getTime()) / (24 * 60 * 60 * 1000)) + 1;
for (let offset = -1; offset <= spanDays; offset++) {
const candidateDay = new Date(Date.UTC(year, month - 1, day + offset));
if (!dowSet.has(candidateDay.getUTCDay())) continue;
const wall = `${candidateDay.toISOString().slice(0, 10)}T${pad(hour)}:${pad(minute)}`;
const startsAt = zonedWallClockToUtc(wall, timeZone);
if (startsAt >= from && startsAt < to) result.push(startsAt);
}
return result;
}
// Monday 00:00 of `now`'s week in `timeZone`.
export function startOfWeekInTimeZone(now: Date, timeZone: string): Date {
const { year, month, day } = wallDateInTimeZone(now, timeZone);
const date = new Date(Date.UTC(year, month - 1, day));
const sinceMonday = (date.getUTCDay() + 6) % 7;
const monday = new Date(Date.UTC(year, month - 1, day - sinceMonday));
return zonedWallClockToUtc(`${monday.toISOString().slice(0, 10)}T00:00`, timeZone);
}