feat: auto populate clientData field when creating permit
This commit is contained in:
@@ -19,6 +19,7 @@ const orgSchema = new mongoose.Schema({
|
|||||||
avatar: String,
|
avatar: String,
|
||||||
type: String,
|
type: String,
|
||||||
isClient: Boolean,
|
isClient: Boolean,
|
||||||
|
licenseNumber: String,
|
||||||
status: String,
|
status: String,
|
||||||
createdAt: Date,
|
createdAt: Date,
|
||||||
createdBy: String,
|
createdBy: String,
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import { getUser } from "../user/user.service";
|
|||||||
import { createNote } from "../note/note.service";
|
import { createNote } from "../note/note.service";
|
||||||
import { createAlert } from "../alert/alert.service";
|
import { createAlert } from "../alert/alert.service";
|
||||||
import { processedModel } from "../processed/processed.schema";
|
import { processedModel } from "../processed/processed.schema";
|
||||||
|
import { orgModel } from "../organization/organization.schema";
|
||||||
|
|
||||||
export async function createPermit(
|
export async function createPermit(
|
||||||
input: CreatePermitInput,
|
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) {
|
if (input.issued) {
|
||||||
const permit = await processedModel.create({
|
const permit = await processedModel.create({
|
||||||
tenantId: user.tenantId,
|
tenantId: user.tenantId,
|
||||||
|
|||||||
Reference in New Issue
Block a user