mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-22 15:06:32 +00:00
feat(server): adopt zod DTOs for the day-note body contracts
This commit is contained in:
@@ -21,6 +21,10 @@ describe('dayNoteCreateRequestSchema', () => {
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts null time/icon (moveDayNote re-sends the nullable entity fields)', () => {
|
||||
expect(dayNoteCreateRequestSchema.safeParse({ text: 'ok', time: null, icon: null }).success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dayNoteUpdateRequestSchema', () => {
|
||||
@@ -29,4 +33,8 @@ describe('dayNoteUpdateRequestSchema', () => {
|
||||
expect(dayNoteUpdateRequestSchema.safeParse({ icon: '🍽️' }).success).toBe(true);
|
||||
expect(dayNoteUpdateRequestSchema.safeParse({ text: 'x'.repeat(501) }).success).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts an explicit null time (clears the label)', () => {
|
||||
expect(dayNoteUpdateRequestSchema.safeParse({ time: null }).success).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,18 +68,21 @@ export const dayUpdateRequestSchema = z.object({
|
||||
});
|
||||
export type DayUpdateRequest = z.infer<typeof dayUpdateRequestSchema>;
|
||||
|
||||
// `time`/`icon` accept null on the wire: the client's moveDayNote re-sends the
|
||||
// entity fields (both nullable on dayNoteSchema) through create, and an explicit
|
||||
// null time on update means "clear" (the legacy raw-body route accepted both).
|
||||
export const dayNoteCreateRequestSchema = z.object({
|
||||
text: z.string().min(1).max(500),
|
||||
time: z.string().max(250).optional(),
|
||||
icon: z.string().optional(),
|
||||
time: z.string().max(250).nullable().optional(),
|
||||
icon: z.string().nullable().optional(),
|
||||
sort_order: z.number().optional(),
|
||||
});
|
||||
export type DayNoteCreateRequest = z.infer<typeof dayNoteCreateRequestSchema>;
|
||||
|
||||
export const dayNoteUpdateRequestSchema = z.object({
|
||||
text: z.string().max(500).optional(),
|
||||
time: z.string().max(250).optional(),
|
||||
icon: z.string().optional(),
|
||||
time: z.string().max(250).nullable().optional(),
|
||||
icon: z.string().nullable().optional(),
|
||||
sort_order: z.number().optional(),
|
||||
});
|
||||
export type DayNoteUpdateRequest = z.infer<typeof dayNoteUpdateRequestSchema>;
|
||||
|
||||
Reference in New Issue
Block a user