diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 164b087c..9ea02b5f 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -303,7 +303,10 @@ export class ProfileEmployeeController extends Controller { // "telephoneNumber", // "avatar", // ], - relations: ["currentSubDistrict", "currentDistrict", "currentProvince"], + relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + order: { + profileAvatars: { createdAt: "DESC" }, + }, where: { id: id }, }); if (profiles) { @@ -313,6 +316,7 @@ export class ProfileEmployeeController extends Controller { } if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); let ImgUrl: any; + let _ImgUrl: any = []; if (profiles?.avatar != null && profiles?.avatarName != null) { // await new CallAPI() // .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) @@ -322,6 +326,26 @@ export class ProfileEmployeeController extends Controller { // .catch(); let req_: any = req; const token_ = "Bearer " + req_.headers.authorization.replace("Bearer ", ""); + + await Promise.all( + await profiles.profileAvatars.slice(-7).map(async (x, i) => { + if (x == null) { + _ImgUrl[i] = null; + } else { + const url = process.env.API_URL + `/salary/file/${x?.avatar}/${x?.avatarName}`; + try { + const response_ = await axios.get(url, { + headers: { + Authorization: `${token_}`, + "Content-Type": "application/json", + api_key: process.env.API_KEY, + }, + }); + _ImgUrl[i] = response_.data.downloadUrl; + } catch {} + } + }), + ); const url = process.env.API_URL + `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`; try { const response_ = await axios.get(url, { @@ -497,6 +521,13 @@ export class ProfileEmployeeController extends Controller { ImgUrl: ImgUrl ? ImgUrl : `https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg`, + ImgUrl1: _ImgUrl[0] ? _ImgUrl[0] : null, + ImgUrl2: _ImgUrl[1] ? _ImgUrl[1] : null, + ImgUrl3: _ImgUrl[2] ? _ImgUrl[2] : null, + ImgUrl4: _ImgUrl[3] ? _ImgUrl[3] : null, + ImgUrl5: _ImgUrl[4] ? _ImgUrl[4] : null, + ImgUrl6: _ImgUrl[5] ? _ImgUrl[5] : null, + ImgUrl7: _ImgUrl[6] ? _ImgUrl[6] : null, }; const certs = await this.certificateRepository.find({