WorkshopTasker/server/api/orders/[id].get.ts
Wroclaw a74e148da4
All checks were successful
Build dev / build (push) Successful in 1m16s
pages/orders and pages/clients: add missing logic in handleSubmit
in clients, adding 1 to total was missing
in orders, adding the added memeber to the list and adding to total was missing
2023-12-19 02:34:45 +01:00

39 lines
854 B
TypeScript

import { defineEventHandler } from "h3";
import { createError } from "#imports";
import { database } from "~/server/utils/database";
import { prismaToWeb } from "~/server/utils/prismaToWeb";
export async function orderExists(id: bigint) {
const exists = await database.order.findUnique({
where: {
id,
},
});
return exists !== null;
}
export async function getOrder(id: bigint) {
const order = await database.order.findUnique({
where: {
id,
},
include: {
imported_products: true,
work: {
include: {
offer: true,
},
},
client: true,
},
});
if (!order) throw createError({ statusCode: 404 });
return order;
}
export default defineEventHandler((e) => {
const key = e.context.params?.id as string;
return getOrder(BigInt(key)).then(prismaToWeb);
});