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

20 lines
493 B
TypeScript
Raw Normal View History

import { defineEventHandler } from "h3";
import { type ResultSetHeader } from "mysql2";
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;
const [result] = await database.query(
"DELETE FROM `orders` WHERE `id` = ?",
[id],
) as unknown as [ResultSetHeader];
if (result.affectedRows === 0) throw createError({ statusCode: 404 });
return null;
});