Add task routes, bug fixes
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user