add alert routes
This commit is contained in:
@@ -11,6 +11,7 @@ import { getFilterObject, getSortObject, PageQueryParams } from "../pagination";
|
||||
import { getUserWithoutPopulate } from "../user/user.service";
|
||||
import mongoose from "mongoose";
|
||||
import { rtsPipeline } from "../utils/pipeline";
|
||||
import { createAlert } from "../alert/alert.service";
|
||||
|
||||
export async function createRts(
|
||||
input: CreateRtsInput,
|
||||
@@ -38,6 +39,15 @@ export async function createRts(
|
||||
createdBy: user.userId ?? null,
|
||||
});
|
||||
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
`New Ready to Submit added`,
|
||||
"team",
|
||||
newRts.client?.toString(),
|
||||
newRts.pid,
|
||||
"rts"
|
||||
);
|
||||
|
||||
return rtsModel
|
||||
.findById(newRts.id)
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
@@ -192,15 +202,28 @@ export async function listRts(
|
||||
export async function updateRts(
|
||||
id: string,
|
||||
input: UpdateRtsInput,
|
||||
tenantId: string
|
||||
user: AuthenticatedUser
|
||||
) {
|
||||
const updatedRts = await rtsModel
|
||||
.findOneAndUpdate({ pid: id, tenantId: tenantId }, input, { new: true })
|
||||
.findOneAndUpdate({ pid: id, tenantId: user.tenantId }, input, {
|
||||
new: true,
|
||||
})
|
||||
.populate({ path: "createdBy", select: "pid name avatar" })
|
||||
.populate({ path: "county", select: "pid name avatar" })
|
||||
.populate({ path: "client", select: "pid name avatar" })
|
||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||
|
||||
if (input.assignedTo) {
|
||||
await createAlert(
|
||||
user.tenantId,
|
||||
`You are assigned to RTS`,
|
||||
"user",
|
||||
user.userId,
|
||||
updatedRts.pid,
|
||||
"rts"
|
||||
);
|
||||
}
|
||||
|
||||
return updatedRts;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user