feata: add relation to service

This commit is contained in:
Methapon2001 2024-06-25 09:54:59 +07:00
parent c79851d074
commit d6fa6dfee1

View file

@ -78,8 +78,15 @@ export class ProductServiceController extends Controller {
${where}
`,
]);
const work = await prisma.work.findMany({
where: { serviceId: { in: result.flatMap((v) => (v.type === "service" ? v.id : [])) } },
});
return {
result,
result: result.map((v) =>
v.type === "service" ? { ...v, work: work.filter((w) => w.serviceId === v.id) || [] } : v,
),
page,
pageSize,
total: +String(total),