owltide/server/api/admin/delete-database.post.ts
Hornwitser 251e83f640
All checks were successful
/ build (push) Successful in 1m12s
/ deploy (push) Successful in 16s
Rename AcountSession to ServerSession
Start the work of clearly distingushing client side types, server side
types and types shared over the API by renaming "AccountSession" and
"Session" names used on the server to "ServerSession".
2025-06-09 16:51:05 +02:00

20 lines
516 B
TypeScript

import { deleteDatbase, readAccounts } from "~/server/database";
export default defineEventHandler(async (event) => {
const session = await requireServerSession(event);
let accounts = await readAccounts();
const sessionAccount = accounts.find(
account => account.id === session.accountId
);
if (!sessionAccount) {
throw Error("Account does not exist");
}
if (sessionAccount.type !== "admin") {
throw createError({
statusCode: 403,
statusMessage: "Forbidden",
});
}
await deleteDatbase();
})