add get notification route
This commit is contained in:
@@ -3,6 +3,7 @@ import { PageQueryParams } from "../pagination";
|
||||
import {
|
||||
createNotification,
|
||||
deleteNotification,
|
||||
getNotification,
|
||||
listNotifications,
|
||||
updateNotification,
|
||||
} 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(
|
||||
req: FastifyRequest,
|
||||
res: FastifyReply
|
||||
|
||||
@@ -3,6 +3,7 @@ import { $notification } from "./notification.schema";
|
||||
import {
|
||||
createNotificationHandler,
|
||||
deleteNotificationHandler,
|
||||
getNotificationHandler,
|
||||
listNotificationsHandler,
|
||||
updateNotificationHandler,
|
||||
} from "./notification.controller";
|
||||
@@ -22,6 +23,18 @@ export async function notificationRoutes(fastify: FastifyInstance) {
|
||||
createNotificationHandler
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/:notifId",
|
||||
{
|
||||
schema: {
|
||||
params: { type: "object", properties: { notifId: { type: "string" } } },
|
||||
},
|
||||
config: { requiredClaims: ["notification:read"] },
|
||||
preHandler: [fastify.authorize],
|
||||
},
|
||||
getNotificationHandler
|
||||
);
|
||||
|
||||
fastify.get(
|
||||
"/",
|
||||
{
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
} from "./notification.schema";
|
||||
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(
|
||||
@@ -31,6 +30,16 @@ export async function createNotification(
|
||||
.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(
|
||||
notifId: string,
|
||||
input: UpdateNotificationInput,
|
||||
|
||||
Reference in New Issue
Block a user