From 9f2c22c003b3ffe3e6f3421f78d191760187c8a3 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 30 Jan 2024 16:00:18 +0700 Subject: [PATCH] edit type, level --- src/controllers/PositionController.ts | 43 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 1ef8ea2c..8933cc90 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -94,14 +94,25 @@ export class PositionController extends Controller { select: [ "id", "posTypeName", - "posTypeRank", - "posLevels" - ] + "posTypeRank" + ], + relations: ["posLevels"], }); if (!posType) { return new HttpSuccess([]); } - return new HttpSuccess(posType); + const mapPosType = posType.map(item => ({ + id: item.id, + posTypeName: item.posTypeName, + posTypeRank: item.posTypeRank, + posLevels: item.posLevels.map((posLevel) => ({ + id: posLevel.id, + posLevelName: posLevel.posLevelName, + posLevelRank: posLevel.posLevelRank, + posLevelAuthority: posLevel.posLevelAuthority + })) + })); + return new HttpSuccess(mapPosType); } catch (error) { return error; } @@ -120,13 +131,11 @@ export class PositionController extends Controller { posLevelName: "นักบริหาร", posLevelRank: 1, posLevelAuthority: "HEAD", - posTypes: [ - { - id: "00000000-0000-0000-0000-000000000000", - posTypeName: "นักบริหาร", - posTypeRank: 1 - } - ] + posTypes: { + id: "00000000-0000-0000-0000-000000000000", + posTypeName: "นักบริหาร", + posTypeRank: 1 + } }, ]) async GetPosLevel() { @@ -149,13 +158,11 @@ export class PositionController extends Controller { posLevelName: item.posLevelName, posLevelRank: item.posLevelRank, posLevelAuthority: item.posLevelAuthority, - posTypes: [ - { - id: item.posType.id, - posTypeName: item.posType.posTypeName, - posTypeRank: item.posType.posTypeRank, - } - ] + posTypes: { + id: item.posType.id, + posTypeName: item.posType.posTypeName, + posTypeRank: item.posType.posTypeRank, + } })); return new HttpSuccess(mapPosLevel); } catch (error) {