forked from Wroclaw/WorkshopTasker
17 lines
589 B
TypeScript
17 lines
589 B
TypeScript
/* global defineEventHandler, readBody, createError */
|
|
|
|
import { checkIsOrder } from "../orders.post";
|
|
import { database as db } from "~/server/utils/database";
|
|
|
|
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]);
|
|
});
|