make custom fields in permits nullable

This commit is contained in:
2025-07-08 17:03:43 +05:30
parent 7f877563b3
commit 58d2a1c96c
2 changed files with 32 additions and 26 deletions

View File

@@ -1,7 +1,7 @@
import { z } from "zod"; import { z } from 'zod';
import mongoose from "mongoose"; import mongoose from 'mongoose';
import { buildJsonSchemas } from "fastify-zod"; import { buildJsonSchemas } from 'fastify-zod';
import { pageMetadata, pageQueryParams } from "../pagination"; import { pageMetadata, pageQueryParams } from '../pagination';
const permitSchema = new mongoose.Schema({ const permitSchema = new mongoose.Schema({
tenantId: { tenantId: {
@@ -16,7 +16,7 @@ const permitSchema = new mongoose.Schema({
county: Object, county: Object,
client: { client: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "organization", ref: 'organization',
}, },
clientData: Object, clientData: Object,
permitDate: Date, permitDate: Date,
@@ -34,7 +34,7 @@ const permitSchema = new mongoose.Schema({
utility: String, utility: String,
assignedTo: { assignedTo: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "user", ref: 'user',
}, },
link: String, link: String,
address: Object, address: Object,
@@ -52,7 +52,7 @@ const permitSchema = new mongoose.Schema({
createdAt: Date, createdAt: Date,
createdBy: { createdBy: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "user", ref: 'user',
}, },
newProcessingStatus: Array, newProcessingStatus: Array,
newPayment: Array, newPayment: Array,
@@ -74,9 +74,9 @@ const permitSchema = new mongoose.Schema({
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true }); }).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
export const permitFields = Object.keys(permitSchema.paths).filter( export const permitFields = Object.keys(permitSchema.paths).filter(
(path) => path !== "__v" (path) => path !== '__v'
); );
export const permitModel = mongoose.model("permit", permitSchema); export const permitModel = mongoose.model('permit', permitSchema);
const permitCore = { const permitCore = {
permitNumber: z.string(), permitNumber: z.string(),
@@ -140,12 +140,13 @@ const listPermitResponse = z.object({
const updatePermitInput = z.object({ const updatePermitInput = z.object({
manualStatus: z.string().nullable().optional(), manualStatus: z.string().nullable().optional(),
utility: z.string().nullable().optional(), utility: z.string().nullable().optional(),
assignedTo: z.string().optional(), assignedTo: z.string().nullable().optional(),
newPayment: z.array(z.any()).optional(), newPayment: z.array(z.any()).optional(),
communityName: z.string().optional(), communityName: z.string().nullable().optional(),
lot: z.string().optional(), lot: z.string().nullable().optional(),
jobNumber: z.string().optional(), block: z.string().nullable().optional(),
startDate: z.date().optional(), jobNumber: z.string().nullable().optional(),
startDate: z.date().nullable().optional(),
}); });
export type CreatePermitInput = z.infer<typeof createPermitInput>; export type CreatePermitInput = z.infer<typeof createPermitInput>;
@@ -160,5 +161,5 @@ export const { schemas: permitSchemas, $ref: $permit } = buildJsonSchemas(
updatePermitInput, updatePermitInput,
pageQueryParams, pageQueryParams,
}, },
{ $id: "permit" } { $id: 'permit' }
); );

View File

@@ -1,7 +1,7 @@
import z from "zod"; import z from 'zod';
import mongoose from "mongoose"; import mongoose from 'mongoose';
import { pageQueryParams } from "../pagination"; import { pageQueryParams } from '../pagination';
import { buildJsonSchemas } from "fastify-zod"; import { buildJsonSchemas } from 'fastify-zod';
const processedSchema = new mongoose.Schema({ const processedSchema = new mongoose.Schema({
tenantId: { tenantId: {
@@ -16,7 +16,7 @@ const processedSchema = new mongoose.Schema({
county: Object, county: Object,
client: { client: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "organization", ref: 'organization',
}, },
clientData: Object, clientData: Object,
permitDate: Date, permitDate: Date,
@@ -34,7 +34,7 @@ const processedSchema = new mongoose.Schema({
utility: String, utility: String,
assignedTo: { assignedTo: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "user", ref: 'user',
}, },
link: String, link: String,
address: Object, address: Object,
@@ -52,7 +52,7 @@ const processedSchema = new mongoose.Schema({
createdAt: Date, createdAt: Date,
createdBy: { createdBy: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: "user", ref: 'user',
}, },
newProcessingStatus: Array, newProcessingStatus: Array,
newPayment: Array, newPayment: Array,
@@ -74,18 +74,23 @@ const processedSchema = new mongoose.Schema({
}).index({ tenantId: 1, permitNumber: 1 }, { unique: true }); }).index({ tenantId: 1, permitNumber: 1 }, { unique: true });
export const processedFields = Object.keys(processedSchema.paths).filter( export const processedFields = Object.keys(processedSchema.paths).filter(
(path) => path !== "__v" (path) => path !== '__v'
); );
export const processedModel = mongoose.model( export const processedModel = mongoose.model(
"processed", 'processed',
processedSchema, processedSchema,
"processed" 'processed'
); );
const updateProcessedInput = z.object({ const updateProcessedInput = z.object({
manualStatus: z.string().nullable().optional(), manualStatus: z.string().nullable().optional(),
utility: z.string().nullable().optional(), utility: z.string().nullable().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 UpdateProcessedInput = z.infer<typeof updateProcessedInput>; export type UpdateProcessedInput = z.infer<typeof updateProcessedInput>;
@@ -95,5 +100,5 @@ export const { schemas: processedSchemas, $ref: $processed } = buildJsonSchemas(
pageQueryParams, pageQueryParams,
updateProcessedInput, updateProcessedInput,
}, },
{ $id: "processed" } { $id: 'processed' }
); );