25 lines
761 B
TypeScript
25 lines
761 B
TypeScript
import { z } from 'zod';
|
|
import { idSchema, optionalText, requiredText } from './shared.schema';
|
|
|
|
export const bookingCreateSchema = z
|
|
.object({
|
|
clientId: requiredText('Client'),
|
|
roomId: requiredText('Room'),
|
|
serviceId: optionalText(80),
|
|
startsAt: requiredText('Start time', 40),
|
|
endsAt: requiredText('End time', 40),
|
|
status: z.enum(['booked', 'confirmed', 'completed', 'cancelled']).default('booked'),
|
|
notes: optionalText(1000)
|
|
})
|
|
.superRefine((data, ctx) => {
|
|
if (data.startsAt && data.endsAt && data.endsAt <= data.startsAt) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
path: ['endsAt'],
|
|
message: 'End time must be after the start time.'
|
|
});
|
|
}
|
|
});
|
|
|
|
export const bookingEditSchema = bookingCreateSchema.safeExtend(idSchema.shape);
|