118 lines
4.0 KiB
TypeScript
118 lines
4.0 KiB
TypeScript
import { z } from 'zod';
|
|
import { timeZoneSchema } from './home.js';
|
|
|
|
const isoDateTimeSchema = z.string().datetime();
|
|
|
|
export const attendanceStatusSchema = z.enum(['PRESENT', 'ABSENT', 'EXCUSED']);
|
|
export type AttendanceStatus = z.output<typeof attendanceStatusSchema>;
|
|
|
|
/* The three levels of the attendance status light, in rule order (best to
|
|
worst). The domain uses them as a type and this schema validates them when
|
|
they travel over the API, so there is a single definition. */
|
|
export const attendanceRiskLevelSchema = z.enum(['ok', 'atencion', 'riesgo_alto']);
|
|
export type AttendanceRiskLevelDto = z.output<typeof attendanceRiskLevelSchema>;
|
|
|
|
export const attendeePaymentStatusSchema = z.enum(['UP_TO_DATE', 'PENDING']);
|
|
export type AttendeePaymentStatus = z.output<typeof attendeePaymentStatusSchema>;
|
|
|
|
export const MarkAttendanceRecordSchema = z.object({
|
|
attendeeId: z.string().min(1),
|
|
status: z.enum(['PRESENT', 'ABSENT']),
|
|
});
|
|
export type MarkAttendanceRecord = z.output<typeof MarkAttendanceRecordSchema>;
|
|
|
|
export const MarkAttendanceSchema = z.object({
|
|
classSessionId: z.string().min(1),
|
|
records: z.array(MarkAttendanceRecordSchema).min(1, 'attendance.empty'),
|
|
});
|
|
export type MarkAttendance = z.output<typeof MarkAttendanceSchema>;
|
|
|
|
export const MarkAttendanceResultSchema = z.object({
|
|
classSessionId: z.string(),
|
|
marked: z.number().int().min(0),
|
|
});
|
|
export type MarkAttendanceResult = z.output<typeof MarkAttendanceResultSchema>;
|
|
|
|
export const NotifyAbsenceSchema = z.object({
|
|
attendeeId: z.string().min(1),
|
|
classSessionId: z.string().min(1),
|
|
});
|
|
export type NotifyAbsence = z.output<typeof NotifyAbsenceSchema>;
|
|
|
|
export const PublicNotifyAbsenceSchema = z.object({
|
|
token: z.string().min(1),
|
|
classSessionId: z.string().min(1),
|
|
});
|
|
export type PublicNotifyAbsence = z.output<typeof PublicNotifyAbsenceSchema>;
|
|
|
|
export const NotifyAbsenceResultSchema = z.object({
|
|
classSessionId: z.string(),
|
|
notified: z.boolean(),
|
|
slotReleased: z.boolean(),
|
|
});
|
|
export type NotifyAbsenceResult = z.output<typeof NotifyAbsenceResultSchema>;
|
|
|
|
export const AbsenceQuerySchema = z.object({
|
|
token: z.string().min(1),
|
|
});
|
|
export type AbsenceQuery = z.output<typeof AbsenceQuerySchema>;
|
|
|
|
export const ClassTodaySchema = z.object({
|
|
sessionId: z.string(),
|
|
groupId: z.string(),
|
|
groupName: z.string(),
|
|
startsAt: isoDateTimeSchema,
|
|
enrolledCount: z.number().int().min(0),
|
|
capacity: z.number().int().min(1).nullable(),
|
|
availableSlots: z.number().int().min(0).nullable(),
|
|
hasAttendance: z.boolean(),
|
|
});
|
|
export type ClassToday = z.output<typeof ClassTodaySchema>;
|
|
export type ClassTodayDto = ClassToday;
|
|
|
|
export const ClassTodayListSchema = z.object({
|
|
data: z.array(ClassTodaySchema),
|
|
});
|
|
export type ClassTodayList = z.output<typeof ClassTodayListSchema>;
|
|
|
|
export const TodayClassesQuerySchema = z.object({
|
|
timeZone: timeZoneSchema.optional(),
|
|
});
|
|
export type TodayClassesQuery = z.output<typeof TodayClassesQuerySchema>;
|
|
|
|
export const SessionStudentSchema = z.object({
|
|
attendeeId: z.string(),
|
|
fullName: z.string(),
|
|
paymentStatus: attendeePaymentStatusSchema,
|
|
attendanceStatus: attendanceStatusSchema.nullable(),
|
|
notifiedAbsence: z.boolean(),
|
|
});
|
|
export type SessionStudent = z.output<typeof SessionStudentSchema>;
|
|
export type SessionStudentDto = SessionStudent;
|
|
|
|
export const SessionStudentsSchema = z.object({
|
|
sessionId: z.string(),
|
|
groupId: z.string(),
|
|
groupName: z.string(),
|
|
startsAt: isoDateTimeSchema,
|
|
students: z.array(SessionStudentSchema),
|
|
});
|
|
export type SessionStudents = z.output<typeof SessionStudentsSchema>;
|
|
|
|
export const AbsenceSessionSchema = z.object({
|
|
sessionId: z.string(),
|
|
groupName: z.string(),
|
|
startsAt: isoDateTimeSchema,
|
|
notified: z.boolean(),
|
|
attendanceStatus: attendanceStatusSchema.nullable(),
|
|
});
|
|
export type AbsenceSession = z.output<typeof AbsenceSessionSchema>;
|
|
|
|
export const AbsenceDetailsSchema = z.object({
|
|
attendeeId: z.string(),
|
|
fullName: z.string(),
|
|
groupName: z.string(),
|
|
sessions: z.array(AbsenceSessionSchema),
|
|
});
|
|
export type AbsenceDetails = z.output<typeof AbsenceDetailsSchema>;
|