Skip to content

Commit

Permalink
fix: review 스키마 타입 검증 완화, disabled 필드 기본값 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Jul 6, 2023
1 parent e1b63f6 commit fc33439
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions backend/src/reviews/controller/reviews.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ type Disabled = 0 | 1 | -1;
const disabledSchema = z.coerce.number().int().refine(
(n): n is Disabled => [-1, 0, 1].includes(n),
(n) => ({ message: `0: 공개, 1: 비공개, -1: 전체 리뷰, 입력값: ${n}` }),
);
).default(-1);

export const queryOptionSchema = z.object({
page: positiveInt.default(0),
limit: positiveInt.default(10),
sort: sortSchema,
});

export const booleanLikeSchema = z.union([
z.boolean(),
z.string().toLowerCase()
.refine((s) => s === 'true' || s === 'false')
.transform((s) => s === 'true'),
]);

export const getReviewsSchema = z.object({
isMyReview: z.boolean().default(false),
isMyReview: booleanLikeSchema.catch(false),
titleOrNickname: z.string().optional(),
disabled: disabledSchema,
}).merge(queryOptionSchema);
Expand Down

0 comments on commit fc33439

Please sign in to comment.