WorkshopTasker/server/api/orders/[id].get.ts

39 lines
834 B
TypeScript
Raw Normal View History

import { defineEventHandler } from "h3";
import { createError } from "#imports";
2023-05-24 09:40:45 +02: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
}
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 });
return order;
2023-05-24 09:40:45 +02:00
}
export default defineEventHandler((e) => {
const key = e.context.params?.id as string;
return getOrder(BigInt(key)).then(prismaToWeb);
2023-05-24 09:40:45 +02:00
});