2023-11-06 02:57:00 +01:00
|
|
|
import { defineEventHandler } from "h3";
|
|
|
|
import { createError } from "#imports";
|
2023-05-24 09:40:45 +02:00
|
|
|
|
2023-11-08 05:35:48 +01:00
|
|
|
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;
|
2023-05-24 09:40:45 +02:00
|
|
|
}
|
|
|
|
|
2023-11-08 05:35:48 +01:00
|
|
|
export async function getOrder(id: bigint) {
|
|
|
|
const order = await database.order.findUnique({
|
|
|
|
where: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
include: {
|
|
|
|
imported_products: true,
|
|
|
|
work: {
|
|
|
|
include: {
|
|
|
|
offer: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2023-05-24 09:40:45 +02:00
|
|
|
|
|
|
|
if (!order) throw createError({ statusCode: 404 });
|
2023-11-08 05:35:48 +01:00
|
|
|
return order;
|
2023-05-24 09:40:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default defineEventHandler((e) => {
|
2023-11-08 05:35:48 +01:00
|
|
|
const key = e.context.params?.id as string;
|
|
|
|
return getOrder(BigInt(key)).then(prismaToWeb);
|
2023-05-24 09:40:45 +02:00
|
|
|
});
|