Add permits module
This commit is contained in:
102
src/permit/permit.schema.ts
Normal file
102
src/permit/permit.schema.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { z } from "zod";
|
||||
import mongoose from "mongoose";
|
||||
import { buildJsonSchemas } from "fastify-zod";
|
||||
import { pageMetadata, pageQueryParams } from "../pagination";
|
||||
|
||||
export const permitModel = mongoose.model(
|
||||
"permit",
|
||||
new mongoose.Schema({
|
||||
tenantId: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
pid: {
|
||||
type: String,
|
||||
unique: true,
|
||||
},
|
||||
permitNumber: String,
|
||||
county: {
|
||||
type: mongoose.Types.ObjectId,
|
||||
ref: "organization",
|
||||
},
|
||||
client: {
|
||||
type: mongoose.Types.ObjectId,
|
||||
ref: "organization",
|
||||
},
|
||||
permitDate: Date,
|
||||
stage: String,
|
||||
status: String,
|
||||
assignedTo: {
|
||||
type: mongoose.Types.ObjectId,
|
||||
ref: "user",
|
||||
},
|
||||
createdAt: Date,
|
||||
updatedAt: Date,
|
||||
createdBy: String,
|
||||
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true })
|
||||
);
|
||||
|
||||
const permitCore = {
|
||||
permitNumber: z.string(),
|
||||
county: z.string().optional(),
|
||||
client: z.string().optional(),
|
||||
permitDate: z.date(),
|
||||
stage: z.string().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(),
|
||||
}),
|
||||
client: z.object({
|
||||
name: z.string(),
|
||||
avatar: z.string().optional(),
|
||||
}),
|
||||
assignedTo: z.object({
|
||||
name: z.string(),
|
||||
avatar: z.string().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
const listPermitResponse = z.object({
|
||||
permits: z.array(getPermitResponse),
|
||||
metadata: pageMetadata,
|
||||
});
|
||||
|
||||
const updatePermitInput = z.object({
|
||||
county: z.string().optional(),
|
||||
client: z.string().optional(),
|
||||
permitDate: z.date().optional(),
|
||||
stage: z.string().optional(),
|
||||
status: z.string().optional(),
|
||||
assignedTo: z.string().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" }
|
||||
);
|
||||
Reference in New Issue
Block a user