diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index cd5b62dd..361d51d1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -299,11 +299,15 @@ export class ProfileController extends Controller { // "telephoneNumber", // "avatar", // ], - relations: ["currentSubDistrict", "currentDistrict", "currentProvince"], + relations: ["currentSubDistrict", "currentDistrict", "currentProvince", "profileAvatars"], + order: { + profileAvatars: { createdAt: "DESC" }, + }, where: { id: id }, }); if (!profiles) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - let ImgUrl: any; + let ImgUrl: any = null; + let _ImgUrl: any = []; if (profiles?.avatar != null && profiles?.avatarName != null) { // await new CallAPI() // .GetData(req, `/salary/file/${profiles?.avatar}/${profiles?.avatarName}`) @@ -314,6 +318,26 @@ export class ProfileController extends Controller { 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, { @@ -488,6 +512,13 @@ export class ProfileController 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({