feat: auto populate clientData field when creating permit
This commit is contained in:
@@ -19,6 +19,7 @@ const orgSchema = new mongoose.Schema({
|
||||
avatar: String,
|
||||
type: String,
|
||||
isClient: Boolean,
|
||||
licenseNumber: String,
|
||||
status: String,
|
||||
createdAt: Date,
|
||||
createdBy: String,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user