add notes on update
This commit is contained in:
@@ -11,6 +11,8 @@ import { permitPipeline } from "../utils/pipeline";
|
||||
import { AuthenticatedUser } from "../auth";
|
||||
import mongoose from "mongoose";
|
||||
import { noteModel } from "../note/note.schema";
|
||||
import { getUser } from "../user/user.service";
|
||||
import { createNote } from "../note/note.service";
|
||||
|
||||
export async function createPermit(
|
||||
input: CreatePermitInput,
|
||||
@@ -181,15 +183,27 @@ export async function updatePermit(
|
||||
|
||||
if (updatePermitResult) {
|
||||
for (const key in input) {
|
||||
if (["manualStatus", "utility"].includes(key)) {
|
||||
await noteModel.create({
|
||||
tenantId: user.tenantId,
|
||||
pid: generateId(),
|
||||
resourceId: permitId,
|
||||
content: `Updated ${key} to '${input[key]}'`,
|
||||
createdAt: new Date(),
|
||||
createdBy: user.userId,
|
||||
});
|
||||
if (["manualStatus", "utility", "assignedTo"].includes(key)) {
|
||||
let msg = "";
|
||||
|
||||
if (input[key] === null) {
|
||||
msg = `Cleared ${key}`;
|
||||
} else if (key == "assignedTo") {
|
||||
const user = await getUser(input.assignedTo);
|
||||
if (!user) continue;
|
||||
|
||||
msg = `Assigned to ${user.firstName + " " + user.lastName}`;
|
||||
} else {
|
||||
msg = `Updated ${key} to '${input[key]}'`;
|
||||
}
|
||||
|
||||
await createNote(
|
||||
{
|
||||
content: msg,
|
||||
},
|
||||
permitId,
|
||||
user
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user