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); });