simple-review-server/src/types.ts
2024-09-09 12:24:24 -04:00

37 lines
1,018 B
TypeScript

import { object, string, number, InferType } from "yup";
import { Request } from "express";
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();
export const typeJson = { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json" };
export const userReviewSchema = object({
username: string().min(2).max(30).required(),
rating: rating,
title: string().max(50).notRequired(),
content: string().max(2000).notRequired(),
});
export const serverReviewSchema = userReviewSchema.shape({
id: string().length(6).required(),
timestamp: string().required(),
});
export type UserSideReview = InferType<typeof userReviewSchema>;
export type ServerSideReview = InferType<typeof serverReviewSchema>;
export type userRating = InferType<typeof rating>;
export interface IdRequest extends Request {
params: {
id: string;
};
}