diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 6643ca7f..5ddb2f43 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -63,6 +63,9 @@ import { CommandSign } from "../entities/CommandSign"; import { RoleKeycloak } from "../entities/RoleKeycloak"; import axios from "axios"; import querystring from "querystring"; +import { SubDistrict } from "../entities/SubDistrict"; +import { District } from "../entities/District"; +import { Province } from "../entities/Province"; @Route("api/v1/org/command") @Tags("Command") @@ -99,6 +102,9 @@ export class CommandController extends Controller { private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private commandSignRepository = AppDataSource.getRepository(CommandSign); private roleKeycloakRepo = AppDataSource.getRepository(RoleKeycloak); + private provinceRepo = AppDataSource.getRepository(Province); + private districtRepo = AppDataSource.getRepository(District); + private subDistrictRepo = AppDataSource.getRepository(SubDistrict); /** * API list รายการคำสั่ง @@ -3719,6 +3725,7 @@ export class CommandController extends Controller { const roleKeycloak = await this.roleKeycloakRepo.findOne({ where: { name: Like("USER") }, }); + const null_: any = null; await Promise.all( body.data.map(async (item) => { const before = null; @@ -3780,6 +3787,37 @@ export class CommandController extends Controller { })), ); // if (!result) throw new Error("Failed. Cannot set user's role."); + let registrationProvinceId = await this.provinceRepo.findOneBy({ + id: profile.registrationProvinceId, + }); + profile.registrationProvinceId = registrationProvinceId + ? registrationProvinceId.id + : null_; + let registrationDistrictId = await this.districtRepo.findOneBy({ + id: profile.registrationDistrictId, + }); + profile.registrationDistrictId = registrationDistrictId + ? registrationDistrictId.id + : null_; + let registrationSubDistrictId = await this.subDistrictRepo.findOneBy({ + id: profile.registrationSubDistrictId, + }); + profile.registrationSubDistrictId = registrationSubDistrictId + ? registrationSubDistrictId.id + : null_; + + let currentProvinceId = await this.provinceRepo.findOneBy({ + id: profile.currentProvinceId, + }); + profile.currentProvinceId = currentProvinceId ? currentProvinceId.id : null_; + let currentDistrictId = await this.districtRepo.findOneBy({ + id: profile.currentDistrictId, + }); + profile.currentDistrictId = currentDistrictId ? currentDistrictId.id : null_; + let currentSubDistrictId = await this.subDistrictRepo.findOneBy({ + id: profile.currentSubDistrictId, + }); + profile.currentSubDistrictId = currentSubDistrictId ? currentSubDistrictId.id : null_; profile.keycloak = typeof userKeycloakId === "string" ? userKeycloakId : ""; profile.roleKeycloaks = result && roleKeycloak ? [roleKeycloak] : []; profile.email = item.bodyProfile.email;