2024-09-15 14:59:21 +02:00
|
|
|
import { apiRoute, applyConfig, auth } from "@/api";
|
|
|
|
|
import { createRoute } from "@hono/zod-openapi";
|
2024-11-04 10:43:30 +01:00
|
|
|
import { RolePermissions } from "@versia/kit/tables";
|
2024-04-16 08:48:36 +02:00
|
|
|
import { z } from "zod";
|
2024-12-30 18:00:23 +01:00
|
|
|
import { ApiError } from "~/classes/errors/api-error";
|
2024-09-15 14:59:21 +02:00
|
|
|
import { ErrorSchema } from "~/types/api";
|
2024-04-16 08:48:36 +02:00
|
|
|
|
|
|
|
|
export const meta = applyConfig({
|
|
|
|
|
route: "/api/v1/notifications/destroy_multiple",
|
|
|
|
|
ratelimits: {
|
|
|
|
|
max: 100,
|
|
|
|
|
duration: 60,
|
|
|
|
|
},
|
|
|
|
|
auth: {
|
|
|
|
|
required: true,
|
|
|
|
|
oauthPermissions: ["write:notifications"],
|
|
|
|
|
},
|
2024-06-08 06:57:29 +02:00
|
|
|
permissions: {
|
2024-06-13 04:26:43 +02:00
|
|
|
required: [RolePermissions.ManageOwnNotifications],
|
2024-06-08 06:57:29 +02:00
|
|
|
},
|
2024-04-16 08:48:36 +02:00
|
|
|
});
|
|
|
|
|
|
2024-05-06 09:16:33 +02:00
|
|
|
export const schemas = {
|
|
|
|
|
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 18:20:22 +01:00
|
|
|
middleware: [auth(meta.auth, meta.permissions)] as const,
|
2024-09-15 14:59:21 +02:00
|
|
|
request: {
|
|
|
|
|
query: schemas.query,
|
|
|
|
|
},
|
|
|
|
|
responses: {
|
|
|
|
|
200: {
|
|
|
|
|
description: "Notifications dismissed",
|
|
|
|
|
},
|
|
|
|
|
401: {
|
|
|
|
|
description: "Unauthorized",
|
|
|
|
|
content: {
|
|
|
|
|
"application/json": {
|
|
|
|
|
schema: ErrorSchema,
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-05-06 09:16:33 +02:00
|
|
|
},
|
2024-09-15 14:59:21 +02:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default apiRoute((app) =>
|
|
|
|
|
app.openapi(route, async (context) => {
|
|
|
|
|
const { user } = context.get("auth");
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
2024-12-30 18:00:23 +01:00
|
|
|
throw new ApiError(401, "Unauthorized");
|
2024-09-15 14:59:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
);
|