feat: auto populate clientData field when creating permit

This commit is contained in:
2025-09-30 17:48:44 +05:30
parent cf22145156
commit 65107918a6
2 changed files with 14 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ const orgSchema = new mongoose.Schema({
avatar: String,
type: String,
isClient: Boolean,
licenseNumber: String,
status: String,
createdAt: Date,
createdBy: String,

View File

@@ -19,6 +19,7 @@ import { getUser } from "../user/user.service";
import { createNote } from "../note/note.service";
import { createAlert } from "../alert/alert.service";
import { processedModel } from "../processed/processed.schema";
import { orgModel } from "../organization/organization.schema";
export async function createPermit(
input: CreatePermitInput,
@@ -31,6 +32,18 @@ export async function createPermit(
};
}
if (input.client && !input.clientData) {
const client = await orgModel.findById(input.client);
if (client) {
input.clientData = {
pid: client.pid,
licenseNumber: client.licenseNumber,
name: client.name,
avatar: client.avatar,
};
}
}
if (input.issued) {
const permit = await processedModel.create({
tenantId: user.tenantId,