From 44bf22808109fb13d8b3ef8faaa7bdeff85cfa56 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 2 Apr 2024 13:18:59 +0700 Subject: [PATCH] feat: include relation response when create and delete --- src/controllers/branch/branch-controller.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/controllers/branch/branch-controller.ts b/src/controllers/branch/branch-controller.ts index 197ec21..20828b1 100644 --- a/src/controllers/branch/branch-controller.ts +++ b/src/controllers/branch/branch-controller.ts @@ -127,6 +127,11 @@ export class BranchController extends Controller { const { provinceId, districtId, subDistrictId, headOfficeId, ...rest } = body; return await prisma.branch.create({ + include: { + province: true, + district: true, + subDistrict: true, + }, data: { ...rest, isHeadOffice: headOfficeId === null, @@ -198,7 +203,14 @@ export class BranchController extends Controller { @Delete("{branchId}") async deleteBranch(@Path() branchId: string) { - const record = await prisma.branch.findFirst({ where: { id: branchId } }); + const record = await prisma.branch.findFirst({ + include: { + province: true, + district: true, + subDistrict: true, + }, + where: { id: branchId }, + }); if (!record) { throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.");