WorkshopTasker/server/api/orders/[id].delete.ts

23 lines
479 B
TypeScript
Raw Permalink Normal View History

import { defineEventHandler } from "h3";
2023-05-24 09:40:45 +02:00
import { database } from "~/server/utils/database";
import { createError } from "#imports";
2023-05-24 09:40:45 +02:00
export default defineEventHandler(async (e) => {
const id = e.context.params?.id as string;
2023-05-24 09:40:45 +02:00
try {
await database.order.delete({
where: {
id: BigInt(id),
},
});
} catch (e) {
// FIXME: should be 500 on errors other than "RecordNotFound"
throw createError({ statusCode: 404 });
}
2023-05-24 09:40:45 +02:00
return null;
});