Add task routes, bug fixes

This commit is contained in:
2025-01-29 15:44:24 +05:30
parent 405338c314
commit a157cb3fed
10 changed files with 413 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
import { buildJsonSchemas } from "fastify-zod";
import mongoose from "mongoose";
import z from "zod";
import { files } from "../file/file.schema";
import { pageQueryParams } from "../pagination";
const rtsSchema = new mongoose.Schema({
@@ -58,33 +59,6 @@ export const rtsFields = Object.keys(rtsSchema.paths).filter(
export const rtsModel = mongoose.model("rts", rtsSchema, "rts");
const files = z
.object({
pid: z.string().optional(),
name: z.string(),
type: z.enum(["folder", "file"]),
size: z.number().optional(),
files: z.array(z.lazy(() => files)).optional(),
})
.superRefine((data, ctx) => {
const validateRecursive = (file: any) => {
if (file.type === "file" && !file.pid) {
ctx.addIssue({
path: ["pid"],
message: 'pid is required when type is "file"',
code: z.ZodIssueCode.custom,
});
}
if (file.files) {
file.files.forEach((nestedFile: any) => {
validateRecursive(nestedFile);
});
}
};
validateRecursive(data);
});
const rtsCreateInput = z.object({
county: z.string(),
client: z.string().optional(),