add notification routes
This commit is contained in:
44
src/notification/notification.controller.ts
Normal file
44
src/notification/notification.controller.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user