refactor: enforce type validation using z.union for tmdbId and mbId
This commit is contained in:
@@ -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() }),
|
||||
])
|
||||
);
|
||||
|
||||
@@ -12,13 +12,18 @@ import { z } from 'zod';
|
||||
|
||||
const blacklistRoutes = Router();
|
||||
|
||||
export const blacklistAdd = z.object({
|
||||
tmdbId: z.coerce.number().optional(),
|
||||
mbId: z.string().optional(),
|
||||
mediaType: z.nativeEnum(MediaType),
|
||||
title: z.coerce.string().optional(),
|
||||
user: z.coerce.number(),
|
||||
});
|
||||
export const blacklistAdd = z
|
||||
.object({
|
||||
mediaType: z.nativeEnum(MediaType),
|
||||
title: z.coerce.string().optional(),
|
||||
user: z.coerce.number(),
|
||||
})
|
||||
.and(
|
||||
z.union([
|
||||
z.object({ tmdbId: z.coerce.number() }),
|
||||
z.object({ mbId: z.coerce.string() }),
|
||||
])
|
||||
);
|
||||
|
||||
const blacklistGet = z.object({
|
||||
take: z.coerce.number().int().positive().default(25),
|
||||
|
||||
Reference in New Issue
Block a user