2025-02-14 16:44:32 +01:00
|
|
|
import { apiRoute, auth, reusedResponses } from "@/api";
|
2025-02-05 21:49:39 +01:00
|
|
|
import { createRoute, z } from "@hono/zod-openapi";
|
2025-03-22 18:04:47 +01:00
|
|
|
import { RolePermission } from "@versia/client/schemas";
|
2024-04-16 08:48:36 +02:00
|
|
|
|
2024-12-30 20:26:56 +01:00
|
|
|
const schemas = {
|
2024-05-06 09:16:33 +02:00
|
|
|
query: z.object({
|
|
|
|
|
"ids[]": z.array(z.string().uuid()),
|
|
|
|
|
}),
|
|
|
|
|
};
|
2024-04-16 08:48:36 +02:00
|
|
|
|
2024-09-15 14:59:21 +02:00
|
|
|
const route = createRoute({
|
|
|
|
|
method: "delete",
|
|
|
|
|
path: "/api/v1/notifications/destroy_multiple",
|
|
|
|
|
summary: "Dismiss multiple notifications",
|
2024-12-30 19:18:31 +01:00
|
|
|
middleware: [
|
|
|
|
|
auth({
|
|
|
|
|
auth: true,
|
2025-03-22 18:04:47 +01:00
|
|
|
permissions: [RolePermission.ManageOwnNotifications],
|
2024-12-30 19:18:31 +01:00
|
|
|
scopes: ["write:notifications"],
|
|
|
|
|
}),
|
|
|
|
|
] as const,
|
2024-09-15 14:59:21 +02:00
|
|
|
request: {
|
|
|
|
|
query: schemas.query,
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Notifications dismissed",
|
|
|
|
|
},
|
2025-02-14 16:44:32 +01:00
|
|
|
401: reusedResponses[401],
|
2024-09-15 14:59:21 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
const { user } = context.get("auth");
|
|
|
|
|
|
|
|
|
|
const { "ids[]": ids } = context.req.valid("query");
|
|
|
|
|
|
2024-11-04 10:43:30 +01:00
|
|
|
await user.clearSomeNotifications(ids);
|
2024-09-15 14:59:21 +02:00
|
|
|
|
2024-12-07 13:24:24 +01:00
|
|
|
return context.text("", 200);
|
2024-09-15 14:59:21 +02:00
|
|
|
}),
|
2024-08-19 20:06:38 +02:00
|
|
|
);
|