WorkshopTasker/server/api/orders/[id].patch.ts
Wroclaw eebf25198d Replace mysql2 with prisma
also I updated packages,
and properly typed api input
a lot of time was spent, I don't remeber what really I did x3
but everything was related to replacing mysql2 with prisma
2023-11-08 05:36:12 +01:00

27 lines
763 B
TypeScript

import { defineEventHandler, readBody } from "h3";
import { checkIsOrder } from "../orders.post";
import { getOrder } from "./[id].get";
import { database } from "~/server/utils/database";
import { prismaToWeb } from "~/server/utils/prismaToWeb";
import { createError } from "#imports";
export default defineEventHandler(async (e) => {
const body = await readBody(e);
const id = e.context.params?.id as string;
if (!checkIsOrder(body, true)) throw createError({ message: "Invalid body", statusCode: 400 });
await database.order.update({
where: {
id: BigInt(id),
},
data: {
clientId: body.clientId ? BigInt(body.clientId) : undefined,
draft: body.draft,
},
});
return getOrder(BigInt(id)).then(prismaToWeb);
});