move/create position controller
This commit is contained in:
parent
d1934c1d22
commit
83a5d87a9b
3 changed files with 170 additions and 126 deletions
|
|
@ -26,9 +26,7 @@ import { OrgRoot } from "../entities/OrgRoot";
|
||||||
import { OrgChild2 } from "../entities/OrgChild2";
|
import { OrgChild2 } from "../entities/OrgChild2";
|
||||||
import { OrgChild3 } from "../entities/OrgChild3";
|
import { OrgChild3 } from "../entities/OrgChild3";
|
||||||
import { OrgChild4 } from "../entities/OrgChild4";
|
import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
import { PosExecutive } from "../entities/PosExecutive";
|
|
||||||
import { PosType } from "../entities/PosType";
|
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
|
||||||
@Route("api/v1/org")
|
@Route("api/v1/org")
|
||||||
@Tags("Organization")
|
@Tags("Organization")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -44,9 +42,7 @@ export class OrganizationController extends Controller {
|
||||||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||||
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
|
||||||
private posTypeRepository = AppDataSource.getRepository(PosType)
|
|
||||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
|
||||||
/**
|
/**
|
||||||
* API รายการประวัติโครงสร้าง
|
* API รายการประวัติโครงสร้าง
|
||||||
*
|
*
|
||||||
|
|
@ -535,124 +531,4 @@ export class OrganizationController extends Controller {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* API รายการตำแหน่งทางการบริหาร
|
|
||||||
*
|
|
||||||
* @summary ORG_026 - รายการตำแหน่งทางการบริหาร (ADMIN) #28
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("pos/executive")
|
|
||||||
@Example([
|
|
||||||
{
|
|
||||||
id: "00000000-0000-0000-0000-000000000000",
|
|
||||||
posExecutiveName: "นักบริหาร",
|
|
||||||
posExecutivePriority: 1
|
|
||||||
},
|
|
||||||
])
|
|
||||||
async GetPosExecutive() {
|
|
||||||
try {
|
|
||||||
const posExecutive = await this.posExecutiveRepository.find({
|
|
||||||
select: [
|
|
||||||
"id",
|
|
||||||
"posExecutiveName",
|
|
||||||
"posExecutivePriority"
|
|
||||||
]
|
|
||||||
});
|
|
||||||
if (!posExecutive) {
|
|
||||||
return new HttpSuccess([]);
|
|
||||||
}
|
|
||||||
return new HttpSuccess(posExecutive);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API รายการประเภทตำแหน่ง
|
|
||||||
*
|
|
||||||
* @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("pos/type")
|
|
||||||
@Example([
|
|
||||||
{
|
|
||||||
id: "00000000-0000-0000-0000-000000000000",
|
|
||||||
posTypeName: "นักบริหาร",
|
|
||||||
posTypeRank: 1
|
|
||||||
},
|
|
||||||
])
|
|
||||||
async GetPosType() {
|
|
||||||
try {
|
|
||||||
const posType = await this.posTypeRepository.find({
|
|
||||||
select: [
|
|
||||||
"id",
|
|
||||||
"posTypeName",
|
|
||||||
"posTypeRank",
|
|
||||||
]
|
|
||||||
});
|
|
||||||
if (!posType) {
|
|
||||||
return new HttpSuccess([]);
|
|
||||||
}
|
|
||||||
return new HttpSuccess(posType);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API รายการระดับตำแหน่ง
|
|
||||||
*
|
|
||||||
* @summary ORG_028 - รายการระดับตำแหน่ง (ADMIN) #30
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("pos/level")
|
|
||||||
@Example([
|
|
||||||
{
|
|
||||||
id: "00000000-0000-0000-0000-000000000000",
|
|
||||||
posLevelName: "นักบริหาร",
|
|
||||||
posLevelRank: 1,
|
|
||||||
posLevelAuthority: "HEAD",
|
|
||||||
posTypes: [
|
|
||||||
{
|
|
||||||
id: "00000000-0000-0000-0000-000000000000",
|
|
||||||
posTypeName: "นักบริหาร",
|
|
||||||
posTypeRank: 1
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
])
|
|
||||||
async GetPosLevel() {
|
|
||||||
try {
|
|
||||||
const posLevel = await this.posLevelRepository.find({
|
|
||||||
select: [
|
|
||||||
"id",
|
|
||||||
"posLevelName",
|
|
||||||
"posLevelRank",
|
|
||||||
"posLevelAuthority",
|
|
||||||
"posTypeId"
|
|
||||||
],
|
|
||||||
relations: ["posType"],
|
|
||||||
});
|
|
||||||
if (!posLevel) {
|
|
||||||
return new HttpSuccess([]);
|
|
||||||
}
|
|
||||||
const mapPosLevel = posLevel.map(item => ({
|
|
||||||
id: item.id,
|
|
||||||
posLevelName: item.posLevelName,
|
|
||||||
posLevelRank: item.posLevelRank,
|
|
||||||
posLevelAuthority: item.posLevelAuthority,
|
|
||||||
posTypes: [
|
|
||||||
{
|
|
||||||
id: item.posType.id,
|
|
||||||
posTypeName: item.posType.posTypeName,
|
|
||||||
posTypeRank: item.posType.posTypeRank,
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
return new HttpSuccess(mapPosLevel);
|
|
||||||
} catch (error) {
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
165
src/controllers/PositionController.ts
Normal file
165
src/controllers/PositionController.ts
Normal file
|
|
@ -0,0 +1,165 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Patch,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
Example,
|
||||||
|
SuccessResponse,
|
||||||
|
Response,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
import { PosExecutive } from "../entities/PosExecutive";
|
||||||
|
import { PosType } from "../entities/PosType";
|
||||||
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
|
@Route("api/v1/org/pos")
|
||||||
|
@Tags("Position")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class PositionController extends Controller {
|
||||||
|
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
||||||
|
private posTypeRepository = AppDataSource.getRepository(PosType)
|
||||||
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการตำแหน่งทางการบริหาร
|
||||||
|
*
|
||||||
|
* @summary ORG_026 - รายการตำแหน่งทางการบริหาร (ADMIN) #28
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("executive")
|
||||||
|
@Example([
|
||||||
|
{
|
||||||
|
id: "00000000-0000-0000-0000-000000000000",
|
||||||
|
posExecutiveName: "นักบริหาร",
|
||||||
|
posExecutivePriority: 1
|
||||||
|
},
|
||||||
|
])
|
||||||
|
async GetPosExecutive() {
|
||||||
|
try {
|
||||||
|
const posExecutive = await this.posExecutiveRepository.find({
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"posExecutiveName",
|
||||||
|
"posExecutivePriority"
|
||||||
|
]
|
||||||
|
});
|
||||||
|
if (!posExecutive) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
return new HttpSuccess(posExecutive);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการประเภทตำแหน่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_027 - รายการประเภทตำแหน่ง (ADMIN) #29
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("type")
|
||||||
|
@Example([
|
||||||
|
{
|
||||||
|
id: "00000000-0000-0000-0000-000000000000",
|
||||||
|
posTypeName: "นักบริหาร",
|
||||||
|
posTypeRank: 1,
|
||||||
|
posLevels: [
|
||||||
|
{
|
||||||
|
id : "00000000-0000-0000-0000-000000000000",
|
||||||
|
posLevelName : "นักบริหาร",
|
||||||
|
posLevelRank : 1,
|
||||||
|
posLevelAuthority : "HEAD",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
])
|
||||||
|
async GetPosType() {
|
||||||
|
try {
|
||||||
|
const posType = await this.posTypeRepository.find({
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"posTypeName",
|
||||||
|
"posTypeRank",
|
||||||
|
"posLevels"
|
||||||
|
]
|
||||||
|
});
|
||||||
|
if (!posType) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
return new HttpSuccess(posType);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการระดับตำแหน่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_028 - รายการระดับตำแหน่ง (ADMIN) #30
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("level")
|
||||||
|
@Example([
|
||||||
|
{
|
||||||
|
id: "00000000-0000-0000-0000-000000000000",
|
||||||
|
posLevelName: "นักบริหาร",
|
||||||
|
posLevelRank: 1,
|
||||||
|
posLevelAuthority: "HEAD",
|
||||||
|
posTypes: [
|
||||||
|
{
|
||||||
|
id: "00000000-0000-0000-0000-000000000000",
|
||||||
|
posTypeName: "นักบริหาร",
|
||||||
|
posTypeRank: 1
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
])
|
||||||
|
async GetPosLevel() {
|
||||||
|
try {
|
||||||
|
const posLevel = await this.posLevelRepository.find({
|
||||||
|
select: [
|
||||||
|
"id",
|
||||||
|
"posLevelName",
|
||||||
|
"posLevelRank",
|
||||||
|
"posLevelAuthority",
|
||||||
|
"posTypeId"
|
||||||
|
],
|
||||||
|
relations: ["posType"],
|
||||||
|
});
|
||||||
|
if (!posLevel) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
const mapPosLevel = posLevel.map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
posLevelName: item.posLevelName,
|
||||||
|
posLevelRank: item.posLevelRank,
|
||||||
|
posLevelAuthority: item.posLevelAuthority,
|
||||||
|
posTypes: [
|
||||||
|
{
|
||||||
|
id: item.posType.id,
|
||||||
|
posTypeName: item.posType.posTypeName,
|
||||||
|
posTypeRank: item.posType.posTypeRank,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}));
|
||||||
|
return new HttpSuccess(mapPosLevel);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -43,6 +43,9 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "OrgChild4", "description": "โครงสร้างระดับ 4"
|
"name": "OrgChild4", "description": "โครงสร้างระดับ 4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Position", "description": "ตำแหน่ง"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue