Wroclaw
a74e148da4
All checks were successful
Build dev / build (push) Successful in 1m16s
in clients, adding 1 to total was missing in orders, adding the added memeber to the list and adding to total was missing
39 lines
854 B
TypeScript
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);
|
|
});
|