144 lines
3.5 KiB
TypeScript
144 lines
3.5 KiB
TypeScript
import { buildJsonSchemas } from "fastify-zod";
|
|
import mongoose, { Schema } 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,
|
|
},
|
|
permitType: String,
|
|
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 },
|
|
),
|
|
status: String,
|
|
labels: [String],
|
|
dueDate: Date,
|
|
priority: String,
|
|
createdAt: Date,
|
|
createdBy: {
|
|
type: mongoose.Types.ObjectId,
|
|
ref: "user",
|
|
},
|
|
assignedTo: {
|
|
type: [Schema.Types.ObjectId],
|
|
ref: "user",
|
|
},
|
|
assignedToOrg: String,
|
|
taggedUsers: Array,
|
|
taggedOrgs: Array,
|
|
fileValidationStatus: String,
|
|
permitNumber: [String],
|
|
lot: [String],
|
|
});
|
|
|
|
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(),
|
|
permitType: z.string().optional(),
|
|
labels: z.array(z.string()).optional(),
|
|
priority: z.string().optional(),
|
|
dueDate: z.date().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(),
|
|
assignedTo: z.array(z.string()).optional(),
|
|
assignedToOrg: z.enum(["client", "agent"]).nullable().optional(),
|
|
status: z.string().optional(),
|
|
permitNumber: z.array(z.string()).optional(),
|
|
lot: z.array(z.string()).optional(),
|
|
});
|
|
|
|
const rtsUpdateInput = z.object({
|
|
county: z.string().optional(),
|
|
client: z.string().optional(),
|
|
permitType: z.string().optional(),
|
|
labels: z.array(z.string()).optional(),
|
|
priority: z.string().optional(),
|
|
dueDate: z.date().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(),
|
|
assignedTo: z.array(z.string()).optional(),
|
|
assignedToOrg: z.enum(["client", "agent"]).nullable().optional(),
|
|
status: z.string().optional(),
|
|
fileValidationStatus: z.string().optional(),
|
|
permitNumber: z.array(z.string()).optional(),
|
|
lot: z.array(z.string()).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" },
|
|
);
|