125 lines
2.8 KiB
TypeScript
125 lines
2.8 KiB
TypeScript
import { FastifyInstance } from "fastify";
|
|
import { $notification } from "./notification.schema";
|
|
import {
|
|
createNotificationHandler,
|
|
deleteNotificationHandler,
|
|
getNotificationHandler,
|
|
listNotificationsHandler,
|
|
updateNotificationHandler,
|
|
} from "./notification.controller";
|
|
import { noteRoutes } from "../note/note.route";
|
|
import { getUniqueFields } from "../unique";
|
|
|
|
export async function notificationRoutes(fastify: FastifyInstance) {
|
|
fastify.post(
|
|
"/",
|
|
{
|
|
schema: {
|
|
body: $notification("createNotificationInput"),
|
|
},
|
|
config: { requiredClaims: ["notification:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
createNotificationHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/:notifId",
|
|
{
|
|
schema: {
|
|
params: { type: "object", properties: { notifId: { type: "string" } } },
|
|
},
|
|
config: { requiredClaims: ["notification:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
getNotificationHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/",
|
|
{
|
|
schema: {
|
|
querystring: $notification("pageQueryParams"),
|
|
},
|
|
config: { requiredClaims: ["notification:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
listNotificationsHandler
|
|
);
|
|
|
|
fastify.patch(
|
|
"/:notifId",
|
|
{
|
|
schema: {
|
|
params: { type: "object", properties: { notifId: { type: "string" } } },
|
|
body: $notification("updateNotificationInput"),
|
|
},
|
|
config: { requiredClaims: ["notification:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
updateNotificationHandler
|
|
);
|
|
|
|
fastify.delete(
|
|
"/:notifId",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
notifId: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
config: { requiredClaims: ["notification:delete"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
deleteNotificationHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/search",
|
|
{
|
|
schema: {
|
|
querystring: $notification("pageQueryParams"),
|
|
},
|
|
|
|
config: { requiredClaims: ["notification:delete"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
listNotificationsHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/fields/:field",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
field: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
config: { requiredClaims: ["notification:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
async (req, res) => {
|
|
const { field } = req.params as { field: string };
|
|
|
|
try {
|
|
const uniqueValues = await getUniqueFields(
|
|
field,
|
|
"notifications",
|
|
req.user
|
|
);
|
|
return res.code(200).send(uniqueValues);
|
|
} catch (err) {
|
|
return err;
|
|
}
|
|
}
|
|
);
|
|
|
|
await noteRoutes(fastify);
|
|
}
|