add get notification route
This commit is contained in:
@@ -3,6 +3,7 @@ import { PageQueryParams } from "../pagination";
|
|||||||
import {
|
import {
|
||||||
createNotification,
|
createNotification,
|
||||||
deleteNotification,
|
deleteNotification,
|
||||||
|
getNotification,
|
||||||
listNotifications,
|
listNotifications,
|
||||||
updateNotification,
|
updateNotification,
|
||||||
} from "./notification.service";
|
} from "./notification.service";
|
||||||
@@ -25,6 +26,22 @@ export async function createNotificationHandler(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getNotificationHandler(
|
||||||
|
req: FastifyRequest,
|
||||||
|
res: FastifyReply
|
||||||
|
) {
|
||||||
|
const { notifId } = req.params as { notifId: string };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const notification = await getNotification(notifId, req.user);
|
||||||
|
if (!notification)
|
||||||
|
return res.code(404).send({ error: "resource not found" });
|
||||||
|
return res.code(200).send(notification);
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function listNotificationsHandler(
|
export async function listNotificationsHandler(
|
||||||
req: FastifyRequest,
|
req: FastifyRequest,
|
||||||
res: FastifyReply
|
res: FastifyReply
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { $notification } from "./notification.schema";
|
|||||||
import {
|
import {
|
||||||
createNotificationHandler,
|
createNotificationHandler,
|
||||||
deleteNotificationHandler,
|
deleteNotificationHandler,
|
||||||
|
getNotificationHandler,
|
||||||
listNotificationsHandler,
|
listNotificationsHandler,
|
||||||
updateNotificationHandler,
|
updateNotificationHandler,
|
||||||
} from "./notification.controller";
|
} from "./notification.controller";
|
||||||
@@ -22,6 +23,18 @@ export async function notificationRoutes(fastify: FastifyInstance) {
|
|||||||
createNotificationHandler
|
createNotificationHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fastify.get(
|
||||||
|
"/:notifId",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
params: { type: "object", properties: { notifId: { type: "string" } } },
|
||||||
|
},
|
||||||
|
config: { requiredClaims: ["notification:read"] },
|
||||||
|
preHandler: [fastify.authorize],
|
||||||
|
},
|
||||||
|
getNotificationHandler
|
||||||
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/",
|
"/",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import {
|
|||||||
} from "./notification.schema";
|
} from "./notification.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 { permitModel } from "../permit/permit.schema";
|
|
||||||
import { createAlert } from "../alert/alert.service";
|
import { createAlert } from "../alert/alert.service";
|
||||||
|
|
||||||
export async function createNotification(
|
export async function createNotification(
|
||||||
@@ -31,6 +30,16 @@ export async function createNotification(
|
|||||||
.populate({ path: "assignedTo", select: "pid name avatar" });
|
.populate({ path: "assignedTo", select: "pid name avatar" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getNotification(
|
||||||
|
notifId: string,
|
||||||
|
user: AuthenticatedUser
|
||||||
|
) {
|
||||||
|
return await notificationModel.findOne({
|
||||||
|
tenantId: user.tenantId,
|
||||||
|
pid: notifId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateNotification(
|
export async function updateNotification(
|
||||||
notifId: string,
|
notifId: string,
|
||||||
input: UpdateNotificationInput,
|
input: UpdateNotificationInput,
|
||||||
|
|||||||
Reference in New Issue
Block a user