diff --git a/projects/api/src/contracts/users/schema/response/likedItemResponseSchema.ts b/projects/api/src/contracts/users/schema/response/likedItemResponseSchema.ts index fc7d19f..53c2f38 100644 --- a/projects/api/src/contracts/users/schema/response/likedItemResponseSchema.ts +++ b/projects/api/src/contracts/users/schema/response/likedItemResponseSchema.ts @@ -70,7 +70,7 @@ export const likedCommentResponseSchema = z.object({ * When using extended 'min', only the id is returned */ comment: commentResponseSchema.partial() - .extend({ id: z.number().int() }), + .extend({ id: z.number().int() }).nullish() }).and(likedExtendedCommentResponseSchema); export const likedListResponseSchema = z.object({ @@ -82,5 +82,5 @@ export const likedListResponseSchema = z.object({ list: z.union([ listResponseSchema.partial(), z.object({ id: z.number().int().nullish() }), - ]), + ]).nullish(), }); diff --git a/projects/api/src/contracts/users/schema/response/userCommentResponseSchema.ts b/projects/api/src/contracts/users/schema/response/userCommentResponseSchema.ts index eb8e6e3..c5eddbc 100644 --- a/projects/api/src/contracts/users/schema/response/userCommentResponseSchema.ts +++ b/projects/api/src/contracts/users/schema/response/userCommentResponseSchema.ts @@ -1,37 +1,15 @@ import { commentResponseSchema } from '../../../_internal/response/commentResponseSchema.ts'; import { episodeResponseSchema } from '../../../_internal/response/episodeResponseSchema.ts'; -import { typedMovieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts'; -import { - showResponseSchema, - typedShowResponseSchema, -} from '../../../_internal/response/showResponseSchema.ts'; +import { movieResponseSchema } from '../../../_internal/response/movieResponseSchema.ts'; +import { showResponseSchema } from '../../../_internal/response/showResponseSchema.ts'; import { z } from '../../../_internal/z.ts'; import { seasonResponseSchema } from '../../../shows/schema/response/seasonResponseSchema.ts'; -const commentedMovieResponseSchema = z.object({ - comment: commentResponseSchema, -}).merge(typedMovieResponseSchema); - -const commentedShowResponseSchema = z.object({ - comment: commentResponseSchema, -}).merge(typedShowResponseSchema); - -const commentedSeasonResponseSchema = z.object({ - type: z.literal('season'), - season: seasonResponseSchema, +export const userCommentResponseSchema = z.object({ + type: z.enum(['movie', 'show', 'season', 'episode']), comment: commentResponseSchema, + movie: movieResponseSchema.nullish(), + show: showResponseSchema.nullish(), + season: seasonResponseSchema.nullish(), + episode: episodeResponseSchema.nullish(), }); - -const commentedEpisodeResponseSchema = z.object({ - type: z.literal('episode'), - episode: episodeResponseSchema, - show: showResponseSchema, - comment: commentResponseSchema, -}); - -export const userCommentResponseSchema = z.discriminatedUnion('type', [ - commentedMovieResponseSchema, - commentedShowResponseSchema, - commentedSeasonResponseSchema, - commentedEpisodeResponseSchema, -]);