simple-review-server/src/types.ts

37 lines
1,018 B
TypeScript
Raw Normal View History

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-09-09 12:24:24 -04:00
export const typeJson = { "Access-Control-Allow-Origin": "*", "Content-Type": "application/json" };
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(),
content: string().max(2000).notRequired(),
2024-08-16 15:04:52 -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:13 -04:00
timestamp: string().required(),
2024-08-21 01:36:33 -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: {
2024-08-27 13:42:13 -04:00
id: string;
};
2024-08-21 11:28:13 -04:00
}