import { defineEventHandler, readBody } from "h3"; import { checkIsOrder } from "../orders.post"; import { database as db } from "~/server/utils/database"; import { createError } from "#imports"; 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]); });