Validate that the rating of a review only contains 1 decimal place

This commit is contained in:
powermaker450 2024-08-18 17:59:11 -04:00
parent ecfe99912b
commit d865b56c63

View file

@ -2,7 +2,11 @@ import { object, string, number, InferType } from "yup";
export const reviewSchema = object({
username: string().required(),
rating: number().positive().max(5).required(),
rating: number().positive().max(5).test(
"maxDigitsAfterDecimal",
"Rating must have at most 1 decimal place",
number => Number.isInteger(number! * 10)
).required(),
content: string(),
});