Files
gruperly/packages/shared/src/schemas/home.ts
Jose Selesan 2e184845e1 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.
2026-09-23 16:24:45 -03:00

64 lines
1.8 KiB
TypeScript

import { z } from 'zod';
import { weekdaySchema } from './enums.js';
import { paymentStatusSchema } from './payments.js';
const isoDateTimeSchema = z.string().datetime();
const timeZoneSchema = z
.string()
.refine((tz) => {
try {
new Intl.DateTimeFormat('en-US', { timeZone: tz });
return true;
} catch {
return false;
}
}, 'Zona horaria IANA inválida');
export { timeZoneSchema };
export const HomeStatsSchema = z.object({
groups: z.number().int().nonnegative(),
attendees: z.number().int().nonnegative(),
pendingPayments: z.number().int().nonnegative(),
pendingAmount: z.number().nonnegative(),
});
export type HomeStats = z.output<typeof HomeStatsSchema>;
export const NextClassSchema = z.object({
groupId: z.string(),
name: z.string(),
days: z.array(weekdaySchema).nullable(),
time: z.string().nullable(),
occurrenceAt: isoDateTimeSchema,
isNow: z.boolean(),
});
export type NextClass = z.output<typeof NextClassSchema>;
export const UpcomingPaymentSchema = z.object({
id: z.string(),
amount: z.coerce.number().positive(),
currency: z.string(),
dueDate: isoDateTimeSchema,
status: paymentStatusSchema,
groupName: z.string(),
attendeeName: z.string(),
});
export type UpcomingPayment = z.output<typeof UpcomingPaymentSchema>;
export const HomeSummarySchema = z.object({
stats: HomeStatsSchema,
nextClass: NextClassSchema.nullable(),
upcomingPayments: z.array(UpcomingPaymentSchema),
});
export type HomeSummary = z.output<typeof HomeSummarySchema>;
export type HomeSummaryDto = HomeSummary;
export type HomeStatsDto = HomeStats;
export type NextClassDto = NextClass;
export type UpcomingPaymentDto = UpcomingPayment;
export const HomeQuerySchema = z.object({
timeZone: timeZoneSchema.optional(),
});
export type HomeQuery = z.output<typeof HomeQuerySchema>;