Files
drop/server/api/v1/notifications/[id]/index.delete.ts
DecDuck c03152f299 Internal server error fixes, 7z fixes, OIDC fixes (#289)
* fix: add no-prisma-delete lint

* fix: typescript for lint

* fix: bump droplet

* fix: oidc scopes override

* fix: type errors

* feat: delete all notifications

* fix: lint

* fix: light mode style fixes
2025-11-30 23:01:52 +11:00

38 lines
928 B
TypeScript

import aclManager from "~/server/internal/acls";
import prisma from "~/server/internal/db/database";
export default defineEventHandler(async (h3) => {
const userId = await aclManager.getUserIdACL(h3, ["notifications:delete"]);
if (!userId) throw createError({ statusCode: 403 });
const notificationId = getRouterParam(h3, "id");
if (!notificationId)
throw createError({
statusCode: 400,
statusMessage: "Missing notification ID",
});
const userIds = [userId];
const hasSystemPerms = await aclManager.allowSystemACL(h3, [
"notifications:delete",
]);
if (hasSystemPerms) {
userIds.push("system");
}
const { count } = await prisma.notification.deleteMany({
where: {
id: notificationId,
userId: { in: userIds },
},
});
if (count == 0)
throw createError({
statusCode: 400,
statusMessage: "Invalid notification ID",
});
return {};
});