add types and schemas

This commit is contained in:
ItsMalma
2025-11-08 13:51:18 +07:00
parent b347ab0250
commit e6386648be
28 changed files with 1082 additions and 101 deletions

34
src/common/schemas.ts Normal file
View File

@@ -0,0 +1,34 @@
import { isValid, parse } from "date-fns";
import z from "zod";
export const timeSchema = z
.string("Must be string.")
.nonempty("Must not be empty.")
.transform((val, ctx) => {
const parsedDate = parse(val, "HH:mm", new Date());
if (!isValid(parsedDate)) {
ctx.issues.push({
code: "custom",
message: "Must be in 'HH:mm' format.",
input: val,
});
return z.NEVER;
}
return val;
});
export const dateSchema = z
.string("Must be string.")
.nonempty("Must not be empty.")
.transform((val, ctx) => {
const parsedDate = parse(val, "YYYY-MM-DD", new Date());
if (!isValid(parsedDate)) {
ctx.issues.push({
code: "custom",
message: "Must be in 'YYYY-MM-DD' format.",
input: val,
});
return z.NEVER;
}
return val;
});