166 lines
3.7 KiB
TypeScript
166 lines
3.7 KiB
TypeScript
import { z } from 'zod';
|
|
import mongoose from 'mongoose';
|
|
import { buildJsonSchemas } from 'fastify-zod';
|
|
import { pageMetadata, pageQueryParams } from '../pagination';
|
|
|
|
const permitSchema = new mongoose.Schema({
|
|
tenantId: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
pid: {
|
|
type: String,
|
|
unique: true,
|
|
},
|
|
permitNumber: String,
|
|
county: Object,
|
|
client: {
|
|
type: mongoose.Types.ObjectId,
|
|
ref: 'organization',
|
|
},
|
|
clientData: Object,
|
|
permitDate: Date,
|
|
stage: new mongoose.Schema(
|
|
{
|
|
pipeline: Array,
|
|
currentStage: Number,
|
|
},
|
|
{ _id: false }
|
|
),
|
|
status: String,
|
|
manualStatus: String,
|
|
cleanStatus: String,
|
|
permitType: String,
|
|
utility: String,
|
|
assignedTo: {
|
|
type: mongoose.Types.ObjectId,
|
|
ref: 'user',
|
|
},
|
|
link: String,
|
|
address: Object,
|
|
recordType: String,
|
|
description: String,
|
|
applicationDetails: Object,
|
|
applicationInfo: Object,
|
|
applicationInfoTable: Object,
|
|
conditions: Array,
|
|
ownerDetails: String,
|
|
parcelInfo: Object,
|
|
paymentData: Object,
|
|
professionalsList: Array,
|
|
inspections: Object,
|
|
createdAt: Date,
|
|
createdBy: {
|
|
type: mongoose.Types.ObjectId,
|
|
ref: 'user',
|
|
},
|
|
newProcessingStatus: Array,
|
|
newPayment: Array,
|
|
newConditions: Array,
|
|
professionals: Object,
|
|
recordId: String,
|
|
relatedRecords: Object,
|
|
accelaStatus: String,
|
|
openDate: Date,
|
|
lastUpdateDate: Date,
|
|
statusUpdated: Date,
|
|
issuedDate: Date,
|
|
communityName: String,
|
|
lot: String,
|
|
block: String,
|
|
jobNumber: String,
|
|
startDate: Date,
|
|
history: Array,
|
|
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
|
|
|
|
export const permitFields = Object.keys(permitSchema.paths).filter(
|
|
(path) => path !== '__v'
|
|
);
|
|
export const permitModel = mongoose.model('permit', permitSchema);
|
|
|
|
const permitCore = {
|
|
permitNumber: z.string(),
|
|
county: z.string().optional(),
|
|
client: z.string().optional(),
|
|
permitDate: z.date(),
|
|
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(),
|
|
status: z.string().optional(),
|
|
assignedTo: z.string().optional(),
|
|
};
|
|
|
|
const createPermitInput = z.object({
|
|
...permitCore,
|
|
});
|
|
|
|
const createPermitResponse = z.object({
|
|
pid: z.string(),
|
|
...permitCore,
|
|
});
|
|
|
|
const getPermitResponse = z.object({
|
|
pid: z.string(),
|
|
...permitCore,
|
|
county: z
|
|
.object({
|
|
name: z.string(),
|
|
avatar: z.string().optional(),
|
|
})
|
|
.optional(),
|
|
client: z
|
|
.object({
|
|
name: z.string(),
|
|
avatar: z.string().optional(),
|
|
})
|
|
.optional(),
|
|
assignedTo: z
|
|
.object({
|
|
name: z.string(),
|
|
avatar: z.string().optional(),
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
const listPermitResponse = z.object({
|
|
permits: z.array(getPermitResponse),
|
|
metadata: pageMetadata,
|
|
});
|
|
|
|
const updatePermitInput = z.object({
|
|
manualStatus: z.string().nullable().optional(),
|
|
utility: z.string().nullable().optional(),
|
|
assignedTo: z.string().nullable().optional(),
|
|
newPayment: z.array(z.any()).optional(),
|
|
communityName: z.string().nullable().optional(),
|
|
lot: z.string().nullable().optional(),
|
|
block: z.string().nullable().optional(),
|
|
jobNumber: z.string().nullable().optional(),
|
|
startDate: z.date().nullable().optional(),
|
|
});
|
|
|
|
export type CreatePermitInput = z.infer<typeof createPermitInput>;
|
|
export type UpdatePermitInput = z.infer<typeof updatePermitInput>;
|
|
|
|
export const { schemas: permitSchemas, $ref: $permit } = buildJsonSchemas(
|
|
{
|
|
createPermitInput,
|
|
createPermitResponse,
|
|
getPermitResponse,
|
|
listPermitResponse,
|
|
updatePermitInput,
|
|
pageQueryParams,
|
|
},
|
|
{ $id: 'permit' }
|
|
);
|