2023-11-06 02:57:00 +01:00
|
|
|
import { defineEventHandler, readBody } from "h3";
|
2023-05-24 09:40:45 +02:00
|
|
|
|
|
|
|
import { checkIsOrder } from "../orders.post";
|
|
|
|
import { database as db } from "~/server/utils/database";
|
|
|
|
|
2023-11-06 02:57:00 +01:00
|
|
|
import { createError } from "#imports";
|
|
|
|
|
2023-05-24 09:40:45 +02:00
|
|
|
export default defineEventHandler(async (e) => {
|
|
|
|
const body = await readBody(e);
|
|
|
|
const id = e.context.params?.id;
|
|
|
|
|
|
|
|
if (!checkIsOrder(e, true)) throw createError({ message: "Invalid body", statusCode: 400 });
|
|
|
|
|
|
|
|
const database = await db.new();
|
|
|
|
await database.beginTransaction();
|
|
|
|
|
|
|
|
for (const [k, v] of Object.entries(body))
|
|
|
|
database.query(`UPDATE TABLE \`orders\` SET \`${k}\` = ? WHERE \`id\` = ?`, [v, id]);
|
|
|
|
});
|