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({ tenantId: { type: String, required: true }, pid: { type: String, required: true, unique: true, }, documents: [ new mongoose.Schema( { files: Array, createdAt: Date, createdBy: { type: mongoose.Types.ObjectId, ref: "user", }, }, { _id: false } ), ], county: { type: mongoose.Types.ObjectId, required: true, ref: "organization", }, client: { type: mongoose.Types.ObjectId, ref: "organization", }, stage: new mongoose.Schema( { pipeline: Array, currentStage: Number, }, { _id: false } ), createdAt: Date, createdBy: { type: mongoose.Types.ObjectId, ref: "user", }, }); export const rtsFields = Object.keys(rtsSchema.paths).filter( (path) => path !== "__v" ); export const rtsModel = mongoose.model("rts", rtsSchema, "rts"); const rtsCreateInput = z.object({ county: z.string(), client: z.string().optional(), files: z.array(files).optional(), stage: z .object({ pipeline: z.array( z.object({ name: z.string(), date: z.date().nullable().optional(), description: z.string().optional(), comment: z.string().optional(), }) ), currentStage: z.number(), }) .optional(), }); const rtsUpdateInput = z.object({ county: z.string().optional(), client: z.string().optional(), stage: z .object({ pipeline: z.array( z.object({ name: z.string(), date: z.date().nullable().optional(), description: z.string().optional(), comment: z.string().optional(), }) ), currentStage: z.number(), }) .optional(), }); const rtsNewUpload = z.object({ files: z.array(files), }); export type CreateRtsInput = z.infer; export type UpdateRtsInput = z.infer; export type UploadRtsInput = z.infer; export const { schemas: rtsSchemas, $ref: $rts } = buildJsonSchemas( { rtsCreateInput, rtsUpdateInput, rtsNewUpload, pageQueryParams, }, { $id: "rts" } );