create alerts when user is assignedTo a resource

This commit is contained in:
2025-06-21 17:59:41 +05:30
parent e821c8d11d
commit ad24708f85
5 changed files with 45 additions and 6 deletions

View File

@@ -1,3 +1,4 @@
import { createAlert } from "../alert/alert.service";
import { AuthenticatedUser } from "../auth";
import { createNote } from "../note/note.service";
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
@@ -49,13 +50,25 @@ export async function createTask(
export async function updateTask(
taskId: string,
input: UpdateTaskInput,
tenantId: string
user: AuthenticatedUser
) {
const updatedTask = await taskModel
.findOneAndUpdate({ tenantId: tenantId, pid: taskId }, input, { new: true })
.findOneAndUpdate({ tenantId: user.tenantId, pid: taskId }, input, {
new: true,
})
.populate({ path: "createdBy", select: "pid name avatar" })
.populate({ path: "assignedTo", select: "pid name avatar" });
if (updatedTask && input.assignedTo) {
await createAlert(
user.tenantId,
`You are assigned to ${updatedTask.title}`,
"user",
user.userId,
updatedTask.pid
);
}
return updatedTask;
}