changemaker.lite/api/dist/modules/map/shifts/shift-series.schemas.js

39 lines
2.1 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateShiftSeriesSchema = exports.createShiftSeriesSchema = void 0;
const zod_1 = require("zod");
const client_1 = require("@prisma/client");
exports.createShiftSeriesSchema = zod_1.z.object({
title: zod_1.z.string().min(1, 'Title is required'),
description: zod_1.z.string().optional(),
startTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/, 'Start time must be HH:MM'),
endTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/, 'End time must be HH:MM'),
location: zod_1.z.string().optional(),
maxVolunteers: zod_1.z.number().int().min(1, 'Must have at least 1 volunteer spot'),
isPublic: zod_1.z.boolean().optional().default(false),
cutId: zod_1.z.string().optional(),
// Recurrence
frequency: zod_1.z.nativeEnum(client_1.RecurrenceFrequency),
daysOfWeek: zod_1.z.array(zod_1.z.number().int().min(0).max(6)).optional(), // 0=Sun, 6=Sat
startDate: zod_1.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Start date must be YYYY-MM-DD'),
endDate: zod_1.z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'End date must be YYYY-MM-DD').optional(),
}).refine((data) => {
// Weekly requires daysOfWeek
if (data.frequency === client_1.RecurrenceFrequency.WEEKLY && !data.daysOfWeek?.length) {
return false;
}
return true;
}, { message: 'Weekly recurrence requires at least one day of week', path: ['daysOfWeek'] });
exports.updateShiftSeriesSchema = zod_1.z.object({
title: zod_1.z.string().min(1).optional(),
description: zod_1.z.string().nullable().optional(),
startTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/).optional(),
endTime: zod_1.z.string().regex(/^\d{2}:\d{2}$/).optional(),
location: zod_1.z.string().nullable().optional(),
maxVolunteers: zod_1.z.number().int().min(1).optional(),
isPublic: zod_1.z.boolean().optional(),
cutId: zod_1.z.string().nullable().optional(),
editMode: zod_1.z.enum(['THIS', 'FUTURE', 'ALL']),
fromDate: zod_1.z.string().regex(/^\d{4}-\d{2}-\d{2}$/).optional(), // Required for FUTURE
});
//# sourceMappingURL=shift-series.schemas.js.map