add notes on update
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
processedModel,
|
||||
UpdateProcessedInput,
|
||||
} from "./processed.schema";
|
||||
import { createNote } from "../note/note.service";
|
||||
|
||||
export async function getProcessedPermit(permitId: String, tenantId: String) {
|
||||
return await processedModel.findOne({
|
||||
@@ -20,7 +21,7 @@ export async function updateProcessed(
|
||||
permitId: string,
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
return await processedModel
|
||||
const updateProcessedResult = await processedModel
|
||||
.findOneAndUpdate(
|
||||
{
|
||||
$and: [{ tenantId: user.tenantId }, { pid: permitId }],
|
||||
@@ -32,6 +33,30 @@ export async function updateProcessed(
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" })
|
||||
.populate({ path: "createdBy", select: "pid name avatar" });
|
||||
|
||||
if (updateProcessedResult) {
|
||||
for (const key in input) {
|
||||
if (["manualStatus", "utility"].includes(key)) {
|
||||
let msg = "";
|
||||
|
||||
if (input[key] === null) {
|
||||
msg = `Cleared ${key}`;
|
||||
} else {
|
||||
msg = `Updated ${key} to '${input[key]}'`;
|
||||
}
|
||||
|
||||
await createNote(
|
||||
{
|
||||
content: msg,
|
||||
},
|
||||
permitId,
|
||||
user
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return updateProcessedResult;
|
||||
}
|
||||
}
|
||||
|
||||
export async function listProcessedPermits(
|
||||
|
||||
Reference in New Issue
Block a user