From ddec8275d85e806b17c2cc81ba2d80fc906b0e74 Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Fri, 14 Jun 2024 09:45:23 +0700 Subject: [PATCH] fix: relation --- src/controllers/employee-controller.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/controllers/employee-controller.ts b/src/controllers/employee-controller.ts index 24408ae..69ec871 100644 --- a/src/controllers/employee-controller.ts +++ b/src/controllers/employee-controller.ts @@ -304,19 +304,19 @@ export class EmployeeController extends Controller { include: { customer: true }, }), ]); - if (body.provinceId && !province) + if (body.provinceId !== province?.id) throw new HttpError( HttpStatus.BAD_REQUEST, "Province cannot be found.", "missing_or_invalid_parameter", ); - if (body.districtId && !district) + if (body.districtId !== district?.id) throw new HttpError( HttpStatus.BAD_REQUEST, "District cannot be found.", "missing_or_invalid_parameter", ); - if (body.subDistrictId && !subDistrict) + if (body.subDistrictId !== subDistrict?.id) throw new HttpError( HttpStatus.BAD_REQUEST, "Sub-district cannot be found.", @@ -395,7 +395,11 @@ export class EmployeeController extends Controller { }, employeeCheckup: { createMany: { - data: employeeCheckup || [], + data: + employeeCheckup?.map((v) => ({ + ...v, + provinceId: !!v.provinceId ? null : v.provinceId, + })) || [], }, }, employeeOtherInfo: {