create alerts when user is assignedTo a resource
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user