From d6fa6dfee1b7203a472fd463bd050960e7c46be5 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:54:59 +0700 Subject: [PATCH] feata: add relation to service --- src/controllers/product-service-controller.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/controllers/product-service-controller.ts b/src/controllers/product-service-controller.ts index c2aab92..d6b9810 100644 --- a/src/controllers/product-service-controller.ts +++ b/src/controllers/product-service-controller.ts @@ -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),