2024-08-16 15:04:52 -04:00
|
|
|
import { object, string, number, InferType } from "yup";
|
2024-08-21 11:28:13 -04:00
|
|
|
import { Request } from "express";
|
2024-08-16 15:04:52 -04:00
|
|
|
|
2024-08-21 02:31:44 -04:00
|
|
|
const 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 === 0,
|
|
|
|
)
|
|
|
|
.required();
|
|
|
|
|
2024-08-21 01:36:33 -04:00
|
|
|
export const typeJson = { "Content-Type": "application/json" };
|
2024-08-21 01:25:49 -04:00
|
|
|
|
2024-08-19 01:46:06 -04:00
|
|
|
export const userReviewSchema = object({
|
|
|
|
username: string().min(2).max(30).required(),
|
2024-08-21 02:31:44 -04:00
|
|
|
rating: rating,
|
2024-08-19 01:00:27 -04:00
|
|
|
title: string().max(50).notRequired(),
|
2024-08-19 00:50:14 -04:00
|
|
|
content: string().max(2000).notRequired(),
|
2024-08-16 15:04:52 -04:00
|
|
|
});
|
|
|
|
|
2024-08-19 01:46:06 -04:00
|
|
|
export const serverReviewSchema = userReviewSchema.shape({
|
2024-08-21 01:36:33 -04:00
|
|
|
id: string().length(6).required(),
|
2024-08-27 13:42:00 -04:00
|
|
|
timestamp: string().required()
|
2024-08-21 01:36:33 -04:00
|
|
|
});
|
2024-08-19 01:46:06 -04:00
|
|
|
|
|
|
|
export type UserSideReview = InferType<typeof userReviewSchema>;
|
|
|
|
export type ServerSideReview = InferType<typeof serverReviewSchema>;
|
2024-08-21 02:31:44 -04:00
|
|
|
export type userRating = InferType<typeof rating>;
|
2024-08-21 11:28:13 -04:00
|
|
|
|
|
|
|
export interface IdRequest extends Request {
|
|
|
|
params: {
|
|
|
|
id: string
|
|
|
|
}
|
|
|
|
}
|