feat: add absence notification and analytics features

- Implemented AbsenceNotifyView for notifying absence with session details.
- Created AnalyticsView for displaying group analytics and managing students at risk.
- Added ClassAttendanceView for marking attendance in classes.
- Defined new schemas for analytics and attendance in shared package.
This commit is contained in:
Jose Selesan
2026-09-23 16:24:45 -03:00
parent a363e9e8fc
commit 2e184845e1
59 changed files with 3854 additions and 23 deletions

View File

@@ -0,0 +1,64 @@
import type { WeekDay } from '@gruperly/shared';
import { todayOccurrence } from '@/modules/home/lib/scheduler';
import type { ClassesDb } from './helpers';
export type TodaySessionCandidate = {
groupId: string;
startsAt: Date;
};
type ScheduledGroup = {
id: string;
days: WeekDay[] | null;
time: string | null;
};
// Calcula qué grupos tienen clase hoy (según days/time y la zona horaria del profesor).
export function buildTodayCandidates(
groups: ScheduledGroup[],
now: Date,
timeZone: string,
): TodaySessionCandidate[] {
const candidates: TodaySessionCandidate[] = [];
for (const group of groups) {
if (!group.days || group.days.length === 0 || !group.time) {
continue;
}
const startsAt = todayOccurrence({
days: group.days,
time: group.time,
now,
timeZone,
});
if (startsAt) {
candidates.push({ groupId: group.id, startsAt });
}
}
return candidates;
}
// Materializa (upsert idempotente) las ClassSession del día y devuelve sus ids.
export async function ensureTodaySessions(
db: Pick<ClassesDb, 'classSession'>,
candidates: TodaySessionCandidate[],
): Promise<string[]> {
const sessionIds: string[] = [];
for (const candidate of candidates) {
const session = await db.classSession.upsert({
where: {
groupId_startsAt: {
groupId: candidate.groupId,
startsAt: candidate.startsAt,
},
},
create: {
groupId: candidate.groupId,
startsAt: candidate.startsAt,
},
update: {},
select: { id: true },
});
sessionIds.push(session.id);
}
return sessionIds;
}