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

View File

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