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 { getUser } from "../user/user.service";
|
||||||
import { createNote } from "../note/note.service";
|
import { createNote } from "../note/note.service";
|
||||||
import { permitModel } from "../permit/permit.schema";
|
import { permitModel } from "../permit/permit.schema";
|
||||||
|
import { createAlert } from "../alert/alert.service";
|
||||||
|
|
||||||
export async function createNotification(
|
export async function createNotification(
|
||||||
input: CreateNotificationInput,
|
input: CreateNotificationInput,
|
||||||
@@ -76,6 +77,15 @@ export async function updateNotification(
|
|||||||
updateNotificationResult.permitId,
|
updateNotificationResult.permitId,
|
||||||
user
|
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 { noteModel } from "../note/note.schema";
|
||||||
import { getUser } from "../user/user.service";
|
import { getUser } from "../user/user.service";
|
||||||
import { createNote } from "../note/note.service";
|
import { createNote } from "../note/note.service";
|
||||||
|
import { createAlert } from "../alert/alert.service";
|
||||||
|
|
||||||
export async function createPermit(
|
export async function createPermit(
|
||||||
input: CreatePermitInput,
|
input: CreatePermitInput,
|
||||||
@@ -206,6 +207,17 @@ export async function updatePermit(
|
|||||||
permitId,
|
permitId,
|
||||||
user
|
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: "client", select: "pid name avatar" })
|
||||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||||
|
|
||||||
if (input.assignedTo) {
|
if (updatedRts && input.assignedTo) {
|
||||||
await createAlert(
|
await createAlert(
|
||||||
user.tenantId,
|
user.tenantId,
|
||||||
`You are assigned to RTS`,
|
`You are assigned to RTS`,
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { FastifyReply, FastifyRequest } from "fastify";
|
import { FastifyReply, FastifyRequest } from "fastify";
|
||||||
import { CreateTaskInput, UpdateTaskInput, UploadTaskInput } from "./task.schema";
|
import {
|
||||||
|
CreateTaskInput,
|
||||||
|
UpdateTaskInput,
|
||||||
|
UploadTaskInput,
|
||||||
|
} from "./task.schema";
|
||||||
import {
|
import {
|
||||||
createTask,
|
createTask,
|
||||||
deleteTask,
|
deleteTask,
|
||||||
@@ -58,7 +62,7 @@ export async function updateTaskHandler(
|
|||||||
const { taskId } = req.params as { taskId: string };
|
const { taskId } = req.params as { taskId: string };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updatedTask = await updateTask(taskId, input, req.user.tenantId);
|
const updatedTask = await updateTask(taskId, input, req.user);
|
||||||
if (!updatedTask)
|
if (!updatedTask)
|
||||||
return res.code(404).send({ error: "resource not found" });
|
return res.code(404).send({ error: "resource not found" });
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { createAlert } from "../alert/alert.service";
|
||||||
import { AuthenticatedUser } from "../auth";
|
import { AuthenticatedUser } from "../auth";
|
||||||
import { createNote } from "../note/note.service";
|
import { createNote } from "../note/note.service";
|
||||||
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||||
@@ -49,13 +50,25 @@ export async function createTask(
|
|||||||
export async function updateTask(
|
export async function updateTask(
|
||||||
taskId: string,
|
taskId: string,
|
||||||
input: UpdateTaskInput,
|
input: UpdateTaskInput,
|
||||||
tenantId: string
|
user: AuthenticatedUser
|
||||||
) {
|
) {
|
||||||
const updatedTask = await taskModel
|
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: "createdBy", select: "pid name avatar" })
|
||||||
.populate({ path: "assignedTo", 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;
|
return updatedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user