77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
import { FastifyInstance } from "fastify";
|
|
import { $notification } from "./notification.schema";
|
|
import {
|
|
createNotificationHandler,
|
|
listNotificationsHandler,
|
|
updateNotificationHandler,
|
|
} from "./notification.controller";
|
|
import { getUniqueValuesNotification } from "./notification.service";
|
|
|
|
export async function notificationRoutes(fastify: FastifyInstance) {
|
|
fastify.post(
|
|
"/",
|
|
{
|
|
schema: {
|
|
body: $notification("createNotificationInput"),
|
|
},
|
|
config: { requiredClaims: ["notification:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
createNotificationHandler
|
|
);
|
|
|
|
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.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 getUniqueValuesNotification(
|
|
field,
|
|
req.user.tenantId
|
|
);
|
|
return res.code(200).send(uniqueValues);
|
|
} catch (err) {
|
|
return err;
|
|
}
|
|
}
|
|
);
|
|
}
|