diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index a7f82978..cd35f4f6 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -133,7 +133,15 @@ export class ProfileController extends Controller { } }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + let ImgUrl: any + if(profile?.avatar != null && profile?.avatarName != null) { + await new CallAPI() + .GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) + .then(async (x) => { + ImgUrl = x.downloadUrl + }) + .catch(); + } const province = await this.provinceRepository.findOneBy({ id: profile.registrationProvinceId, }); @@ -241,6 +249,7 @@ export class ProfileController extends Controller { : "-", PositionName: profile.position != null ? profile.position : "-", OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, + ImgUrl: ImgUrl ? ImgUrl : null }; return new HttpSuccess(mapData); @@ -272,6 +281,16 @@ export class ProfileController extends Controller { relations: ["currentSubDistrict", "currentDistrict", "currentProvince"], where: { id: id }, }); + if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + let ImgUrl: any + if(profiles?.avatar != null && profiles?.avatarName != null) { + await new CallAPI() + .GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) + .then(async (x) => { + ImgUrl = x.downloadUrl + }) + .catch(); + } const profileOc = await this.profileRepo.findOne({ relations: [ "current_holders", @@ -283,7 +302,6 @@ export class ProfileController extends Controller { ], where: { id: id }, }); - if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const orgRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true }, @@ -432,6 +450,7 @@ export class ProfileController extends Controller { ? Extension.ToThaiNumber(profiles.currentProvince.name) : "", // AvatarId: profiles?.avatar ?? null, + ImgUrl: ImgUrl ? ImgUrl : null }; const certs = await this.certificateRepository.find({ diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 1503209b..c123be2b 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -139,7 +139,15 @@ export class ProfileEmployeeController extends Controller { }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profile.id); - + let ImgUrl: any + if(profile?.avatar != null && profile?.avatarName != null) { + await new CallAPI() + .GetData2(req, `/salary/file/${profile?.avatar}/${profile?.avatarName}`) + .then(async (x) => { + ImgUrl = x.downloadUrl + }) + .catch(); + } const province = await this.provinceRepository.findOneBy({ id: profile.registrationProvinceId, }); @@ -247,6 +255,7 @@ export class ProfileEmployeeController extends Controller { : "-", PositionName: profile.position != null ? profile.position : "-", OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, + ImgUrl: ImgUrl ? ImgUrl : null }; return new HttpSuccess(mapData); @@ -280,6 +289,16 @@ export class ProfileEmployeeController extends Controller { if (profiles) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profiles.id); } + if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + let ImgUrl: any + if(profiles?.avatar != null && profiles?.avatarName != null) { + await new CallAPI() + .GetData2(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) + .then(async (x) => { + ImgUrl = x.downloadUrl + }) + .catch(); + } const profileOc = await this.profileRepo.findOne({ relations: [ "current_holders", @@ -291,7 +310,6 @@ export class ProfileEmployeeController extends Controller { ], where: { id: id }, }); - if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profileOc) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const orgRevision = await this.orgRevisionRepo.findOne({ @@ -441,6 +459,7 @@ export class ProfileEmployeeController extends Controller { ? Extension.ToThaiNumber(profiles.currentProvince.name) : "", // AvatarId: profiles?.avatar ?? null, + ImgUrl: ImgUrl ? ImgUrl : null }; const certs = await this.certificateRepository.find({ diff --git a/src/interfaces/call-api.ts b/src/interfaces/call-api.ts index 48c32288..a9188fa1 100644 --- a/src/interfaces/call-api.ts +++ b/src/interfaces/call-api.ts @@ -31,6 +31,23 @@ class CallAPI { throw error; } } + //Get (response.data) + public async GetData2(request: any, @Path() path: any) { + const token = request.headers.authorization; + const url = process.env.API_URL + path; + try { + const response = await axios.get(url, { + headers: { + Authorization: `${token}`, + "Content-Type": "application/json", + api_key: process.env.API_KEY, + }, + }); + return response.data; + } catch (error) { + throw error; + } + } //Post public async PostData(request: any, @Path() path: any, sendData: any) { const token = request.headers.authorization;