Skip to content

Commit 7301116

Browse files
committed
Merge branch 'development' into 'master'
Prepare Version 3.4.2 See merge request dadangnh/iam!318
2 parents e3ab7ed + 108edd9 commit 7301116

File tree

4 files changed

+113
-10
lines changed

4 files changed

+113
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# IAM Changelog
22

3-
## Version 3.4.1 (current stable)
3+
## Version 3.4.2 (current stable)
4+
* add new endpoint api/pegawais/v3/info/from-iam-token
5+
6+
## Version 3.4.1
47
* fix bugs class PosisiHelper
58

69
## Version 3.4.0

config/packages/api_platform.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
api_platform:
22
title: IAM API Docs
3-
version: 3.4.1
3+
version: 3.4.2
44
description: |
55
Bug report and feature request are welcome, please report [here](https://gitlab.com/dadangnh/iam/-/issues).
66
Newest production version are always available at [https://iam.pajak.or.id/api](https://iam.pajak.or.id/api)

src/Controller/Pegawai/PegawaiController.php

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,9 +653,81 @@ public function getPegawaiInfoV2FromUserId(ManagerRegistry $doctrine, Request $r
653653
]
654654
], 200);
655655
}
656-
foreach ($getJabatanPegawai as $jabatanPegawai) {
657-
$levelUnit = $jabatanPegawai->getUnit()->getLevel();
658656

657+
$output = $this->getArrayPegawaiInfo($doctrine, $getJabatanPegawai);
658+
659+
return $this->json([
660+
'status' => 'success',
661+
'code' => 'DATA_FOUND',
662+
'message'=> 'Data ditemukan',
663+
'data' => $output
664+
]);
665+
}
666+
667+
/**
668+
* @param ManagerRegistry $doctrine
669+
* @param Request $request
670+
* @return JsonResponse
671+
* @throws JsonException
672+
*/
673+
#[Route('/api/pegawais/v3/info/from-iam-token', methods: ['POST'])]
674+
public function getPegawaiInfoV3FromUserId(ManagerRegistry $doctrine, Request $request): JsonResponse
675+
{
676+
$user = $this->getUser();
677+
$userNya = $doctrine
678+
->getRepository(User::class)
679+
->findOneBy(['id' => $user->getId()]);
680+
681+
// If no data found, return
682+
if (null === $userNya) {
683+
return $this->json([
684+
'status' => 'fail',
685+
'code' => 'DATA_NOT_FOUND',
686+
'message'=> 'There is no User found with the associated id.',
687+
'data' => [
688+
'additionalInfo' => $userNya
689+
]
690+
], 200);
691+
}
692+
693+
$output = [
694+
'pegawaiId' => $userNya->getPegawai()->getId(),
695+
'nip9' => $userNya->getPegawai()->getNip9(),
696+
'nip18' => $userNya->getPegawai()->getNip18(),
697+
'nama' => $userNya->getPegawai()->getNama(),
698+
'pangkat' => $userNya->getPegawai()->getPangkat(),
699+
'username' => $userNya->getUsername()
700+
];
701+
702+
$getJabatanPegawai = $userNya->getPegawai()->getJabatanPegawais();
703+
704+
// If no data found, return
705+
if (null === $getJabatanPegawai) {
706+
return $this->json([
707+
'status' => 'fail',
708+
'code' => 'DATA_NOT_FOUND',
709+
'message'=> 'There is no Pegawai found with the associated id.',
710+
'data' => [
711+
'additionalInfo' => $userNya
712+
]
713+
], 200);
714+
}
715+
716+
$output = $this->getArrayPegawaiInfo($doctrine, $getJabatanPegawai);
717+
718+
return $this->json([
719+
'status' => 'success',
720+
'code' => 'DATA_FOUND',
721+
'message'=> 'Data ditemukan',
722+
'data' => $output
723+
]);
724+
}
725+
726+
private function getArrayPegawaiInfo($doctrine, $jabatanPegawais): array
727+
{
728+
foreach ($jabatanPegawais as $jabatanPegawai) {
729+
//get level unit
730+
$levelUnit = $jabatanPegawai->getUnit()->getLevel();
659731
//get role by jabatan pegawai object
660732
$rolesJabatan = RoleHelper::getPlainRolesNameFromJabatanPegawai(
661733
$doctrine->getManager(),
@@ -748,12 +820,7 @@ public function getPegawaiInfoV2FromUserId(ManagerRegistry $doctrine, Request $r
748820
$output['jabatanPegawai'][] = $jp;
749821
}
750822

751-
return $this->json([
752-
'status' => 'success',
753-
'code' => 'DATA_FOUND',
754-
'message'=> 'Data ditemukan',
755-
'data' => $output
756-
]);
823+
return $output;
757824
}
758825

759826
private function getUnitEsArray($unit, $level): array {

src/OpenApi/PegawaiCustomDecorator.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ public function __invoke(array $context = []): OpenApi
139139
],
140140
]);
141141

142+
$schemas['infoFromToken'] = new ArrayObject([
143+
'type' => 'object',
144+
'properties' => [
145+
'data' => [
146+
'type' => 'string',
147+
'readOnly' => true,
148+
],
149+
],
150+
]);
151+
142152
$bulkPegawaiDataFromIdsItem = new PathItem(
143153
ref: 'Pegawai',
144154
post: new Operation(
@@ -316,11 +326,34 @@ public function __invoke(array $context = []): OpenApi
316326
),
317327
);
318328

329+
$userInfoFromToken = new PathItem(
330+
ref: 'Token',
331+
post: new Operation(
332+
operationId: 'postInfoFromToken',
333+
tags: ['Token'],
334+
responses: [
335+
'200' => [
336+
'description' => 'Who Am I? This endpoint provide the user information from a token with custom payload, different from /whoami.',
337+
'content' => [
338+
'application/json' => [
339+
'schema' => [
340+
'$ref' => '#/components/schemas/infoFromToken',
341+
],
342+
],
343+
],
344+
],
345+
],
346+
summary: 'Who Am I? This endpoint provide the user information from a token.',
347+
requestBody: null,
348+
),
349+
);
350+
319351
$openApi->getPaths()->addPath('/api/pegawais/mass_fetch', $bulkPegawaiDataFromIdsItem);
320352
$openApi->getPaths()->addPath('/api/pegawais/atasan', $fetchAtasanFromPegawaiIdItem);
321353
$openApi->getPaths()->addPath('/api/pegawais/v2/atasan', $fetchAtasanV2FromPegawaiIdItem);
322354
$openApi->getPaths()->addPath('/api/pegawais/info', $fetchInfoFromJabatanPegawaiIdItem);
323355
$openApi->getPaths()->addPath('/api/pegawais/v2/info', $fetchInfoFromJabatanPegawaiIdItemV2);
356+
$openApi->getPaths()->addPath('/api/pegawais/v3/info/from-iam-token', $userInfoFromToken);
324357
$openApi->getPaths()->addPath('/api-ext/pegawais/v1/info/from-token', $infoFromUserItem);
325358

326359
return $openApi;

0 commit comments

Comments
 (0)