forked from Wroclaw/WorkshopTasker
Wroclaw
eebf25198d
also I updated packages, and properly typed api input a lot of time was spent, I don't remeber what really I did x3 but everything was related to replacing mysql2 with prisma
38 lines
834 B
TypeScript
38 lines
834 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,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
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);
|
|
});
|