2024-08-16 15:04:52 -04:00
|
|
|
import { object, string, number, InferType } from "yup";
|
|
|
|
|
|
|
|
export const reviewSchema = object({
|
2024-08-18 23:30:53 -04:00
|
|
|
username: string().strict(true).max(30).required(),
|
2024-08-18 23:45:00 -04:00
|
|
|
rating: number()
|
|
|
|
.positive()
|
|
|
|
.max(5)
|
|
|
|
.test(
|
|
|
|
"maxDigitsAfterDecimal",
|
|
|
|
"Rating can only have at most one integer at half intervals (.0 or .5)",
|
|
|
|
(number) => {
|
|
|
|
!((number! * 10) % 5);
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.required(),
|
2024-08-18 23:30:53 -04:00
|
|
|
title: string().strict(true).max(50).required(),
|
|
|
|
content: string().strict(true).max(2000).notRequired(),
|
2024-08-16 15:04:52 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export type Review = InferType<typeof reviewSchema>;
|