78 lines
3.1 KiB
TypeScript
78 lines
3.1 KiB
TypeScript
import { z } from 'zod';
|
|
import { SchedulingPollStatus, PollVoteValue } from '@prisma/client';
|
|
|
|
export const createPollSchema = z.object({
|
|
title: z.string().min(1, 'Title is required').max(200),
|
|
description: z.string().max(2000).optional(),
|
|
location: z.string().max(500).optional(),
|
|
timezone: z.string().default('America/Edmonton'),
|
|
allowAnonymous: z.boolean().optional().default(true),
|
|
notifyOnVote: z.boolean().optional().default(true),
|
|
votingDeadline: z.string().datetime().optional(),
|
|
options: z.array(z.object({
|
|
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Date must be YYYY-MM-DD'),
|
|
startTime: z.string().regex(/^\d{2}:\d{2}$/, 'Start time must be HH:MM'),
|
|
endTime: z.string().regex(/^\d{2}:\d{2}$/, 'End time must be HH:MM'),
|
|
})).min(2, 'At least 2 options required').max(20, 'Maximum 20 options'),
|
|
});
|
|
|
|
export const updatePollSchema = z.object({
|
|
title: z.string().min(1).max(200).optional(),
|
|
description: z.string().max(2000).nullable().optional(),
|
|
location: z.string().max(500).nullable().optional(),
|
|
timezone: z.string().optional(),
|
|
allowAnonymous: z.boolean().optional(),
|
|
notifyOnVote: z.boolean().optional(),
|
|
votingDeadline: z.string().datetime().nullable().optional(),
|
|
status: z.nativeEnum(SchedulingPollStatus).optional(),
|
|
});
|
|
|
|
export const addOptionsSchema = z.object({
|
|
options: z.array(z.object({
|
|
date: z.string().regex(/^\d{4}-\d{2}-\d{2}$/, 'Date must be YYYY-MM-DD'),
|
|
startTime: z.string().regex(/^\d{2}:\d{2}$/, 'Start time must be HH:MM'),
|
|
endTime: z.string().regex(/^\d{2}:\d{2}$/, 'End time must be HH:MM'),
|
|
})).min(1).max(20),
|
|
});
|
|
|
|
export const submitVotesSchema = z.object({
|
|
voterName: z.string().min(1, 'Name is required').max(100),
|
|
voterEmail: z.string().email().max(200).optional(),
|
|
voterToken: z.string().optional(),
|
|
votes: z.array(z.object({
|
|
optionId: z.string().min(1),
|
|
value: z.nativeEnum(PollVoteValue),
|
|
})).min(1, 'At least one vote required'),
|
|
});
|
|
|
|
export const submitCommentSchema = z.object({
|
|
authorName: z.string().min(1, 'Name is required').max(100),
|
|
content: z.string().min(1, 'Comment is required').max(2000),
|
|
});
|
|
|
|
export const finalizePollSchema = z.object({
|
|
optionId: z.string().min(1, 'Option ID is required'),
|
|
});
|
|
|
|
export const convertToShiftSchema = z.object({
|
|
maxVolunteers: z.number().int().min(1).default(10),
|
|
isPublic: z.boolean().optional().default(true),
|
|
cutId: z.string().optional(),
|
|
});
|
|
|
|
export const listPollsSchema = z.object({
|
|
page: z.coerce.number().int().positive().default(1),
|
|
limit: z.coerce.number().int().positive().max(100).default(20),
|
|
search: z.string().optional(),
|
|
status: z.nativeEnum(SchedulingPollStatus).optional(),
|
|
});
|
|
|
|
export type CreatePollInput = z.infer<typeof createPollSchema>;
|
|
export type UpdatePollInput = z.infer<typeof updatePollSchema>;
|
|
export type AddOptionsInput = z.infer<typeof addOptionsSchema>;
|
|
export type SubmitVotesInput = z.infer<typeof submitVotesSchema>;
|
|
export type SubmitCommentInput = z.infer<typeof submitCommentSchema>;
|
|
export type FinalizePollInput = z.infer<typeof finalizePollSchema>;
|
|
export type ConvertToShiftInput = z.infer<typeof convertToShiftSchema>;
|
|
export type ListPollsInput = z.infer<typeof listPollsSchema>;
|