add notification delete route
This commit is contained in:
@@ -2,6 +2,7 @@ import { FastifyRequest, FastifyReply } from "fastify";
|
|||||||
import { PageQueryParams } from "../pagination";
|
import { PageQueryParams } from "../pagination";
|
||||||
import {
|
import {
|
||||||
createNotification,
|
createNotification,
|
||||||
|
deleteNotification,
|
||||||
listNotifications,
|
listNotifications,
|
||||||
updateNotification,
|
updateNotification,
|
||||||
} from "./notification.service";
|
} from "./notification.service";
|
||||||
@@ -63,3 +64,20 @@ export async function updateNotificationHandler(
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteNotificationHandler(
|
||||||
|
req: FastifyRequest,
|
||||||
|
res: FastifyReply
|
||||||
|
) {
|
||||||
|
const { notifId } = req.params as { notifId: string };
|
||||||
|
|
||||||
|
try {
|
||||||
|
const deleteResult = await deleteNotification(notifId, req.user.tenantId);
|
||||||
|
if (deleteResult.deletedCount == 0)
|
||||||
|
return res.code(404).send({ error: "resource not found" });
|
||||||
|
|
||||||
|
return res.code(204).send();
|
||||||
|
} catch (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { FastifyInstance } from "fastify";
|
|||||||
import { $notification } from "./notification.schema";
|
import { $notification } from "./notification.schema";
|
||||||
import {
|
import {
|
||||||
createNotificationHandler,
|
createNotificationHandler,
|
||||||
|
deleteNotificationHandler,
|
||||||
listNotificationsHandler,
|
listNotificationsHandler,
|
||||||
updateNotificationHandler,
|
updateNotificationHandler,
|
||||||
} from "./notification.controller";
|
} from "./notification.controller";
|
||||||
@@ -45,6 +46,24 @@ export async function notificationRoutes(fastify: FastifyInstance) {
|
|||||||
updateNotificationHandler
|
updateNotificationHandler
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fastify.delete(
|
||||||
|
"/:notifId",
|
||||||
|
{
|
||||||
|
schema: {
|
||||||
|
params: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
notifId: { type: "string" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
config: { requiredClaims: ["notification:delete"] },
|
||||||
|
preHandler: [fastify.authorize],
|
||||||
|
},
|
||||||
|
deleteNotificationHandler
|
||||||
|
);
|
||||||
|
|
||||||
fastify.get(
|
fastify.get(
|
||||||
"/fields/:field",
|
"/fields/:field",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -90,6 +90,12 @@ export async function listNotifications(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function deleteNotification(notifId: string, tenantId: string) {
|
||||||
|
return await notificationModel.deleteOne({
|
||||||
|
$and: [{ tenantId: tenantId }, { pid: notifId }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export async function getUniqueValuesNotification(
|
export async function getUniqueValuesNotification(
|
||||||
field: string,
|
field: string,
|
||||||
tenenatId: string
|
tenenatId: string
|
||||||
|
|||||||
Reference in New Issue
Block a user