create alerts when user is assignedTo a resource
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
import { getUser } from "../user/user.service";
|
||||
import { createNote } from "../note/note.service";
|
||||
import { permitModel } from "../permit/permit.schema";
|
||||
import { createAlert } from "../alert/alert.service";
|
||||
|
||||
export async function createNotification(
|
||||
input: CreateNotificationInput,
|
||||
@@ -76,6 +77,15 @@ export async function updateNotification(
|
||||
updateNotificationResult.permitId,
|
||||
user
|
||||
);
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
``,
|
||||
"user",
|
||||
user.userId,
|
||||
updateNotificationResult.permitId,
|
||||
"permits"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import mongoose from "mongoose";
|
||||
import { noteModel } from "../note/note.schema";
|
||||
import { getUser } from "../user/user.service";
|
||||
import { createNote } from "../note/note.service";
|
||||
import { createAlert } from "../alert/alert.service";
|
||||
|
||||
export async function createPermit(
|
||||
input: CreatePermitInput,
|
||||
@@ -206,6 +207,17 @@ export async function updatePermit(
|
||||
permitId,
|
||||
user
|
||||
);
|
||||
|
||||
if (key == "assignedTo") {
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
`You are assigned to ${updatePermitResult.permitNumber}`,
|
||||
"user",
|
||||
user.userId,
|
||||
updatePermitResult.pid,
|
||||
"permits"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ export async function updateRts(
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||
|
||||
if (input.assignedTo) {
|
||||
if (updatedRts && input.assignedTo) {
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
`You are assigned to RTS`,
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import { FastifyReply, FastifyRequest } from "fastify";
|
||||
import { CreateTaskInput, UpdateTaskInput, UploadTaskInput } from "./task.schema";
|
||||
import {
|
||||
CreateTaskInput,
|
||||
UpdateTaskInput,
|
||||
UploadTaskInput,
|
||||
} from "./task.schema";
|
||||
import {
|
||||
createTask,
|
||||
deleteTask,
|
||||
@@ -58,7 +62,7 @@ export async function updateTaskHandler(
|
||||
const { taskId } = req.params as { taskId: string };
|
||||
|
||||
try {
|
||||
const updatedTask = await updateTask(taskId, input, req.user.tenantId);
|
||||
const updatedTask = await updateTask(taskId, input, req.user);
|
||||
if (!updatedTask)
|
||||
return res.code(404).send({ error: "resource not found" });
|
||||
|
||||
@@ -111,4 +115,4 @@ export async function newFilesHandler(req: FastifyRequest, res: FastifyReply) {
|
||||
} catch (err) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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