feat: auto update clientData field when client field is updated for permits and processed permits
This commit is contained in:
@@ -235,7 +235,6 @@ export async function updatePermit(
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
|
||||
@@ -274,6 +273,19 @@ export async function updatePermit(
|
||||
"permits"
|
||||
);
|
||||
}
|
||||
} else if (key == "client") {
|
||||
const orgInDb = await orgModel.findById(input.client);
|
||||
if (orgInDb) {
|
||||
updatePermitResult.clientData = {
|
||||
pid: orgInDb.pid,
|
||||
licenseNumber: orgInDb.licenseNumber,
|
||||
name: orgInDb.name,
|
||||
avatar: orgInDb.avatar,
|
||||
};
|
||||
|
||||
updatePermitResult.markModified("clientData");
|
||||
await updatePermitResult.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ export const processedModel = mongoose.model(
|
||||
);
|
||||
|
||||
const updateProcessedInput = z.object({
|
||||
client: z.string().optional(),
|
||||
manualStatus: z.string().nullable().optional(),
|
||||
utility: z.string().nullable().optional(),
|
||||
communityName: z.string().nullable().optional(),
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
import { createNote } from "../note/note.service";
|
||||
import { createAlert } from "../alert/alert.service";
|
||||
import { getUser } from "../user/user.service";
|
||||
import { orgModel } from "../organization/organization.schema";
|
||||
|
||||
export async function getProcessedPermit(permitId: String, tenantId: String) {
|
||||
return await processedModel
|
||||
@@ -38,7 +39,6 @@ export async function updateProcessed(
|
||||
{ new: true }
|
||||
)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
|
||||
@@ -77,6 +77,19 @@ export async function updateProcessed(
|
||||
"processed"
|
||||
);
|
||||
}
|
||||
} else if (key == "client") {
|
||||
const orgInDb = await orgModel.findById(input.client);
|
||||
if (orgInDb) {
|
||||
updateProcessedResult.clientData = {
|
||||
pid: orgInDb.pid,
|
||||
licenseNumber: orgInDb.licenseNumber,
|
||||
name: orgInDb.name,
|
||||
avatar: orgInDb.avatar,
|
||||
};
|
||||
|
||||
updateProcessedResult.markModified("clientData");
|
||||
await updateProcessedResult.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user