add notification routes

This commit is contained in:
2025-02-05 13:52:04 +05:30
parent 8559aab3da
commit 2d62e9712b
8 changed files with 193 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
import { FastifyRequest, FastifyReply } from "fastify";
import { PageQueryParams } from "../pagination";
import { listNotifications, updateNotification } from "./notification.service";
import { UpdateNotificationInput } from "./notification.schema";
export async function listNotificationsHandler(
req: FastifyRequest,
res: FastifyReply
) {
const queryParams = req.query as PageQueryParams;
try {
const notificationList = await listNotifications(
queryParams,
req.user.tenantId
);
return res.code(200).send(notificationList);
} catch (err) {
return err;
}
}
export async function updateNotificationHandler(
req: FastifyRequest,
res: FastifyReply
) {
const input = req.body as UpdateNotificationInput;
const { notifId } = req.params as { notifId: string };
try {
const updatedNotification = await updateNotification(
notifId,
input,
req.user.tenantId
);
if (!updatedNotification)
return res.code(404).send({ error: "resource not found" });
return res.code(200).send(updatedNotification);
} catch (err) {
return err;
}
}