WorkshopTasker/server/api/clients/[id].delete.ts
2023-05-11 06:03:22 +02:00

17 lines
462 B
TypeScript

/* global defineEventHandler, createError */
import { ResultSetHeader } from "mysql2";
import { database } from "~/server/utils/database";
export default defineEventHandler(async (e) => {
const id = e.context.params?.id as string;
const [result] = await database.query(
"DELETE FROM `clients` WHERE `id` = ?",
[id],
) as unknown as [ResultSetHeader];
if (result.affectedRows === 0) throw createError({ statusCode: 404 });
return null;
});