simple-review-server/src/types.ts

27 lines
770 B
TypeScript
Raw Normal View History

2024-08-16 15:04:52 -04:00
import { object, string, number, InferType } from "yup";
export const typeJson = {"Content-Type": "application/json"};
export const userReviewSchema = object({
username: string().min(2).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)",
2024-08-19 00:10:56 -04:00
(number) => (number! * 10) % 5 === 0,
2024-08-18 23:45:00 -04:00
)
.required(),
2024-08-19 01:00:27 -04:00
title: string().max(50).notRequired(),
content: string().max(2000).notRequired(),
2024-08-16 15:04:52 -04:00
});
export const serverReviewSchema = userReviewSchema.shape({
id: string().length(6).required()
})
export type UserSideReview = InferType<typeof userReviewSchema>;
export type ServerSideReview = InferType<typeof serverReviewSchema>;