refactor: enforce type validation using z.union for tmdbId and mbId

This commit is contained in:
Pierre
2025-03-15 13:09:19 +01:00
committed by HiItsStolas
parent 38532bd28a
commit c212858221
2 changed files with 24 additions and 14 deletions

View File

@@ -1,10 +1,15 @@
import { MediaType } from '@server/constants/media';
import { z } from 'zod';
export const watchlistCreate = z.object({
ratingKey: z.coerce.string().optional(),
tmdbId: z.coerce.number().optional(),
mbId: z.coerce.string().optional(),
mediaType: z.nativeEnum(MediaType),
title: z.coerce.string().optional(),
});
export const watchlistCreate = z
.object({
ratingKey: z.coerce.string().optional(),
mediaType: z.nativeEnum(MediaType),
title: z.coerce.string().optional(),
})
.and(
z.union([
z.object({ tmdbId: z.coerce.number() }),
z.object({ mbId: z.coerce.string() }),
])
);