Files
permit-api/src/rts/rts.schema.ts
2025-02-06 15:33:47 +05:30

110 lines
2.4 KiB
TypeScript

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<typeof rtsCreateInput>;
export type UpdateRtsInput = z.infer<typeof rtsUpdateInput>;
export type UploadRtsInput = z.infer<typeof rtsNewUpload>;
export const { schemas: rtsSchemas, $ref: $rts } = buildJsonSchemas(
{
rtsCreateInput,
rtsUpdateInput,
rtsNewUpload,
pageQueryParams,
},
{ $id: "rts" }
);