import { defineEventHandler } from "h3"; import BaaPagination from "../utils/baaPagination"; import { type data, database } from "../utils/database"; import { type client, type orderSummary } from "~/utils/types/database"; export const baaWrapper = new BaaPagination( "orderSummaries", "id", "*, CONVERT(`client`, CHAR) AS `client`, CONVERT(`user`, CHAR) as `user`", ); export default defineEventHandler(async (e) => { const orders = await baaWrapper.RESTget(e, 50, 200); const uniqueClients: Array = []; for (const i of orders) { if (!uniqueClients.includes(i.client)) uniqueClients.push(database.escape(i.client)); } const [clients] = await database.query( ["SELECT", "*,", "CONVERT(`id`, CHAR) AS `id`", "FROM `clients`", "WHERE `id` IN", `(${uniqueClients.join(', ')})`, ].join(" "), ) as data; const rvalue: Array | { client?: client }> = []; for (const i of orders) rvalue.push({ ...i, client: clients.find(e => i.client === e.id) }); return rvalue; });