From 2b72ad39c994abcb2ddff19504a2c68ca26fc145 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 26 Apr 2024 14:41:55 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9C=E0=B8=B9=E0=B9=89=E0=B8=9A=E0=B8=B1?= =?UTF-8?q?=E0=B8=87=E0=B8=84=E0=B8=B1=E0=B8=9A=E0=B8=9B=E0=B8=B1=E0=B8=8D?= =?UTF-8?q?=E0=B8=8A=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 041027fb..b3723fb1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -103,6 +103,63 @@ export class ProfileController extends Controller { })); return new HttpSuccess({ caregiver, commander, chairman }); } + /** + * + * + */ + @Get("commander") + async getProfileCommander(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOne({ + where: { keycloak: request.user.sub }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + const _caregiver = await this.profileRepo.find({ + relations: { posLevel: true, posType: true }, + }); + const _commander = await this.profileRepo.find({ + relations: { posLevel: true, posType: true }, + }); + const _chairman = await this.profileRepo.find({ + relations: { posLevel: true, posType: true }, + }); + + const caregiver = _caregiver.map((_data) => ({ + id: _data.id, + prefix: _data.prefix, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + position: _data.position, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + isDirector: true, + })); + const commander = _commander.map((_data) => ({ + id: _data.id, + prefix: _data.prefix, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + position: _data.position, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + isDirector: true, + })); + const chairman = _chairman.map((_data) => ({ + id: _data.id, + prefix: _data.prefix, + firstName: _data.firstName, + lastName: _data.lastName, + citizenId: _data.citizenId, + position: _data.position, + posLevel: _data.posLevel == null ? null : _data.posLevel.posLevelName, + posType: _data.posType == null ? null : _data.posType.posTypeName, + isDirector: true, + })); + return new HttpSuccess({ caregiver, commander, chairman }); + } /** * API สร้างทะเบียนประวัติ