feat(server): adopt zod DTOs for the day-note body contracts

This commit is contained in:
jubnl
2026-07-26 17:44:25 +02:00
parent 4e49e9c21e
commit 3762d3306c
6 changed files with 46 additions and 44 deletions
+8
View File
@@ -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);
});
});
+7 -4
View File
@@ -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>;