2024-01-30 15:10:11 +07:00
|
|
|
import {
|
|
|
|
|
Controller,
|
|
|
|
|
Get,
|
|
|
|
|
Post,
|
|
|
|
|
Put,
|
|
|
|
|
Delete,
|
|
|
|
|
Patch,
|
|
|
|
|
Route,
|
|
|
|
|
Security,
|
|
|
|
|
Tags,
|
|
|
|
|
Body,
|
|
|
|
|
Path,
|
|
|
|
|
Request,
|
|
|
|
|
Example,
|
|
|
|
|
SuccessResponse,
|
|
|
|
|
Response,
|
2024-01-30 18:01:58 +07:00
|
|
|
Query,
|
2024-01-30 15:10:11 +07:00
|
|
|
} 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";
|
2024-01-30 16:47:39 +07:00
|
|
|
import { CreatePosDict, PosDict } from "../entities/PosDict";
|
2024-01-30 16:02:34 +07:00
|
|
|
import HttpError from "../interfaces/http-error";
|
2024-02-01 11:12:44 +07:00
|
|
|
import { In, IsNull, Like } from "typeorm";
|
2024-01-31 11:00:51 +07:00
|
|
|
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
|
|
|
|
|
import { OrgRevision } from "../entities/OrgRevision";
|
|
|
|
|
import { OrgRoot } from "../entities/OrgRoot";
|
|
|
|
|
import { OrgChild1 } from "../entities/OrgChild1";
|
|
|
|
|
import { OrgChild2 } from "../entities/OrgChild2";
|
|
|
|
|
import { OrgChild3 } from "../entities/OrgChild3";
|
|
|
|
|
import { OrgChild4 } from "../entities/OrgChild4";
|
|
|
|
|
import { Position } from "../entities/Position";
|
2024-01-30 15:10:11 +07:00
|
|
|
@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);
|
2024-01-30 16:02:34 +07:00
|
|
|
private posTypeRepository = AppDataSource.getRepository(PosType);
|
2024-01-30 15:10:11 +07:00
|
|
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
2024-01-30 16:47:39 +07:00
|
|
|
private posDictRepository = AppDataSource.getRepository(PosDict);
|
2024-01-31 11:00:51 +07:00
|
|
|
private posMasterRepository = AppDataSource.getRepository(PosMaster);
|
2024-01-31 15:09:22 +07:00
|
|
|
private positionRepository = AppDataSource.getRepository(Position);
|
2024-01-31 11:00:51 +07:00
|
|
|
|
|
|
|
|
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
|
|
|
|
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
|
|
|
|
private child1Repository = AppDataSource.getRepository(OrgChild1);
|
|
|
|
|
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
|
|
|
|
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
|
|
|
|
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
2024-01-30 15:10:11 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API รายการตำแหน่งทางการบริหาร
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_026 - รายการตำแหน่งทางการบริหาร (ADMIN) #28
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("executive")
|
|
|
|
|
@Example([
|
|
|
|
|
{
|
|
|
|
|
id: "00000000-0000-0000-0000-000000000000",
|
|
|
|
|
posExecutiveName: "นักบริหาร",
|
2024-01-31 11:00:51 +07:00
|
|
|
posExecutivePriority: 1,
|
2024-01-30 15:10:11 +07:00
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
async GetPosExecutive() {
|
|
|
|
|
try {
|
|
|
|
|
const posExecutive = await this.posExecutiveRepository.find({
|
2024-01-31 11:00:51 +07:00
|
|
|
select: ["id", "posExecutiveName", "posExecutivePriority"],
|
2024-01-30 15:10:11 +07:00
|
|
|
});
|
|
|
|
|
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: [
|
|
|
|
|
{
|
2024-01-31 11:00:51 +07:00
|
|
|
id: "00000000-0000-0000-0000-000000000000",
|
|
|
|
|
posLevelName: "นักบริหาร",
|
|
|
|
|
posLevelRank: 1,
|
|
|
|
|
posLevelAuthority: "HEAD",
|
|
|
|
|
},
|
|
|
|
|
],
|
2024-01-30 15:10:11 +07:00
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
async GetPosType() {
|
|
|
|
|
try {
|
|
|
|
|
const posType = await this.posTypeRepository.find({
|
2024-01-31 11:00:51 +07:00
|
|
|
select: ["id", "posTypeName", "posTypeRank"],
|
2024-01-30 16:00:18 +07:00
|
|
|
relations: ["posLevels"],
|
2024-01-30 15:10:11 +07:00
|
|
|
});
|
|
|
|
|
if (!posType) {
|
|
|
|
|
return new HttpSuccess([]);
|
|
|
|
|
}
|
2024-01-31 11:00:51 +07:00
|
|
|
const mapPosType = posType.map((item) => ({
|
2024-01-30 16:00:18 +07:00
|
|
|
id: item.id,
|
|
|
|
|
posTypeName: item.posTypeName,
|
|
|
|
|
posTypeRank: item.posTypeRank,
|
|
|
|
|
posLevels: item.posLevels.map((posLevel) => ({
|
|
|
|
|
id: posLevel.id,
|
|
|
|
|
posLevelName: posLevel.posLevelName,
|
2024-01-31 11:00:51 +07:00
|
|
|
posLevelRank: posLevel.posLevelRank,
|
|
|
|
|
posLevelAuthority: posLevel.posLevelAuthority,
|
|
|
|
|
})),
|
2024-01-30 16:00:18 +07:00
|
|
|
}));
|
|
|
|
|
return new HttpSuccess(mapPosType);
|
2024-01-30 15:10:11 +07:00
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API รายการระดับตำแหน่ง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_028 - รายการระดับตำแหน่ง (ADMIN) #30
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("level")
|
|
|
|
|
@Example([
|
|
|
|
|
{
|
|
|
|
|
id: "00000000-0000-0000-0000-000000000000",
|
|
|
|
|
posLevelName: "นักบริหาร",
|
|
|
|
|
posLevelRank: 1,
|
|
|
|
|
posLevelAuthority: "HEAD",
|
2024-01-30 16:00:18 +07:00
|
|
|
posTypes: {
|
|
|
|
|
id: "00000000-0000-0000-0000-000000000000",
|
|
|
|
|
posTypeName: "นักบริหาร",
|
2024-01-31 11:00:51 +07:00
|
|
|
posTypeRank: 1,
|
|
|
|
|
},
|
2024-01-30 15:10:11 +07:00
|
|
|
},
|
|
|
|
|
])
|
|
|
|
|
async GetPosLevel() {
|
|
|
|
|
try {
|
|
|
|
|
const posLevel = await this.posLevelRepository.find({
|
2024-01-31 11:00:51 +07:00
|
|
|
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
|
2024-01-30 15:10:11 +07:00
|
|
|
relations: ["posType"],
|
|
|
|
|
});
|
|
|
|
|
if (!posLevel) {
|
|
|
|
|
return new HttpSuccess([]);
|
|
|
|
|
}
|
2024-01-31 11:00:51 +07:00
|
|
|
const mapPosLevel = posLevel.map((item) => ({
|
2024-01-30 15:10:11 +07:00
|
|
|
id: item.id,
|
|
|
|
|
posLevelName: item.posLevelName,
|
|
|
|
|
posLevelRank: item.posLevelRank,
|
|
|
|
|
posLevelAuthority: item.posLevelAuthority,
|
2024-01-30 16:00:18 +07:00
|
|
|
posTypes: {
|
|
|
|
|
id: item.posType.id,
|
|
|
|
|
posTypeName: item.posType.posTypeName,
|
|
|
|
|
posTypeRank: item.posType.posTypeRank,
|
2024-01-31 11:00:51 +07:00
|
|
|
},
|
2024-01-30 15:10:11 +07:00
|
|
|
}));
|
|
|
|
|
return new HttpSuccess(mapPosLevel);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-30 16:02:34 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API เพิ่มตำแหน่ง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_030 - เพิ่มตำแหน่ง (ADMIN) #33
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Post("position")
|
|
|
|
|
@Example([
|
|
|
|
|
{
|
|
|
|
|
positionName: "นักบริหาร",
|
|
|
|
|
positionField: "บริหาร",
|
|
|
|
|
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
positionExecutiveField: "นักบริหาร",
|
2024-01-31 11:00:51 +07:00
|
|
|
positionArea: "บริหาร",
|
2024-01-30 16:02:34 +07:00
|
|
|
},
|
|
|
|
|
])
|
2024-01-31 11:00:51 +07:00
|
|
|
async createPosition(
|
|
|
|
|
@Body()
|
|
|
|
|
requestBody: CreatePosDict,
|
|
|
|
|
@Request() request: { user: Record<string, any> },
|
|
|
|
|
) {
|
2024-01-30 16:47:39 +07:00
|
|
|
const posDict = Object.assign(new PosDict(), requestBody);
|
|
|
|
|
if (!posDict) {
|
2024-01-30 16:02:34 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 11:00:51 +07:00
|
|
|
const checkPosTypeId = await this.posTypeRepository.findOne({
|
|
|
|
|
where: { id: requestBody.posTypeId },
|
|
|
|
|
});
|
2024-01-30 16:02:34 +07:00
|
|
|
if (!checkPosTypeId) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 11:00:51 +07:00
|
|
|
const checkPosLevelId = await this.posLevelRepository.findOne({
|
|
|
|
|
where: { id: requestBody.posLevelId },
|
|
|
|
|
});
|
2024-01-30 16:02:34 +07:00
|
|
|
if (!checkPosLevelId) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 11:00:51 +07:00
|
|
|
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({
|
|
|
|
|
where: { id: requestBody.posExecutiveId },
|
|
|
|
|
});
|
2024-01-30 16:02:34 +07:00
|
|
|
if (!checkPosExecutiveId) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2024-01-30 16:47:39 +07:00
|
|
|
posDict.createdUserId = request.user.sub;
|
|
|
|
|
posDict.createdFullName = request.user.name;
|
|
|
|
|
posDict.lastUpdateUserId = request.user.sub;
|
|
|
|
|
posDict.lastUpdateFullName = request.user.name;
|
|
|
|
|
await this.posDictRepository.save(posDict);
|
|
|
|
|
return new HttpSuccess(posDict.id);
|
2024-01-30 16:02:34 +07:00
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-30 16:47:39 +07:00
|
|
|
/**
|
|
|
|
|
* API ลบตำแหน่ง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_032 - ลบตำแหน่ง (ADMIN) #40
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id Id ตำแหน่ง
|
|
|
|
|
*/
|
2024-01-31 15:24:28 +07:00
|
|
|
@Delete("position/{id}")
|
2024-01-30 16:47:39 +07:00
|
|
|
async delete(@Path() id: string) {
|
|
|
|
|
const delPosDict = await this.posDictRepository.findOne({ where: { id } });
|
|
|
|
|
if (!delPosDict) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await this.posDictRepository.remove(delPosDict);
|
|
|
|
|
return new HttpSuccess();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 11:00:51 +07:00
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
/**
|
|
|
|
|
* API ค้นหารายการตำแหน่ง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_029 - ค้นหารายการตำแหน่ง (ADMIN) #32
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Get("position")
|
2024-01-31 15:02:54 +07:00
|
|
|
async findPosition(@Query("keyword") keyword?: string, @Query("type") type?: string) {
|
2024-01-31 11:00:51 +07:00
|
|
|
try {
|
2024-01-30 18:01:58 +07:00
|
|
|
let findPosDict: any;
|
2024-01-31 14:29:39 +07:00
|
|
|
switch (type) {
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionName":
|
2024-01-31 14:29:39 +07:00
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posDictName: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-30 18:01:58 +07:00
|
|
|
if (!findPosDict) {
|
2024-01-31 14:29:39 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionField":
|
2024-01-31 14:29:39 +07:00
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posDictField: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-30 18:01:58 +07:00
|
|
|
if (!findPosDict) {
|
2024-01-31 14:29:39 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionType":
|
2024-01-31 14:29:39 +07:00
|
|
|
const findTypes: PosType[] = await this.posTypeRepository.find({
|
|
|
|
|
where: { posTypeName: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
select: ["id"],
|
|
|
|
|
});
|
|
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posTypeId: In(findTypes.map((x) => x.id)) },
|
|
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionLevel":
|
2024-01-31 14:29:39 +07:00
|
|
|
const findLevel: PosLevel[] = await this.posLevelRepository.find({
|
|
|
|
|
where: { posLevelName: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
select: ["id"],
|
|
|
|
|
});
|
|
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posLevelId: In(findLevel.map((x) => x.id)) },
|
|
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionExecutive":
|
2024-01-31 14:29:39 +07:00
|
|
|
const findExecutive: PosExecutive[] = await this.posExecutiveRepository.find({
|
|
|
|
|
where: { posExecutiveName: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
select: ["id"],
|
|
|
|
|
});
|
|
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posExecutiveId: In(findExecutive.map((x) => x.id)) },
|
|
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionExecutiveField":
|
2024-01-31 14:29:39 +07:00
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posDictExecutiveField: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-30 18:01:58 +07:00
|
|
|
if (!findPosDict) {
|
2024-01-31 14:29:39 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
2024-01-30 18:01:58 +07:00
|
|
|
case "positionArea":
|
2024-01-31 14:29:39 +07:00
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
where: { posDictArea: Like(`%${keyword}%`) },
|
2024-01-31 15:02:54 +07:00
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
2024-01-31 14:29:39 +07:00
|
|
|
});
|
2024-01-30 18:01:58 +07:00
|
|
|
if (!findPosDict) {
|
2024-01-31 14:29:39 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล " + keyword);
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 13:16:22 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2024-01-31 15:02:54 +07:00
|
|
|
findPosDict = await this.posDictRepository.find({
|
|
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
|
|
|
|
});
|
2024-01-31 13:16:22 +07:00
|
|
|
if (!findPosDict) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
|
|
|
|
break;
|
2024-01-30 18:01:58 +07:00
|
|
|
}
|
2024-01-31 13:16:22 +07:00
|
|
|
|
2024-01-31 14:29:39 +07:00
|
|
|
const mapDataPosDict = await Promise.all(
|
|
|
|
|
findPosDict.map(async (item: any) => {
|
|
|
|
|
return {
|
|
|
|
|
id: item.id,
|
|
|
|
|
positionName: item.posDictName,
|
|
|
|
|
positionField: item.posDictField,
|
|
|
|
|
posTypeId: item.posTypeId,
|
2024-01-31 15:02:54 +07:00
|
|
|
posTypeName: item.posType == null ? null : item.posType.posTypeName,
|
2024-01-31 14:29:39 +07:00
|
|
|
posLevelId: item.posLevelId,
|
2024-01-31 15:02:54 +07:00
|
|
|
posLevelName: item.posLevel == null ? null : item.posLevel.posLevelName,
|
2024-01-31 14:29:39 +07:00
|
|
|
posExecutiveId: item.posExecutiveId,
|
2024-01-31 15:02:54 +07:00
|
|
|
posExecutiveName: item.posExecutive == null ? null : item.posExecutive.posExecutiveName,
|
2024-01-31 14:29:39 +07:00
|
|
|
positionExecutiveField: item.posDictExecutiveField,
|
|
|
|
|
positionArea: item.posDictArea,
|
|
|
|
|
positionIsSelected: false,
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
);
|
2024-01-31 13:16:22 +07:00
|
|
|
|
|
|
|
|
return new HttpSuccess(mapDataPosDict);
|
2024-01-31 14:29:39 +07:00
|
|
|
} catch (error) {
|
2024-01-30 18:01:58 +07:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-31 11:00:51 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API เพิ่มอัตรากำลัง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_033 - เพิ่มอัตรากำลัง (ADMIN) #35
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Post("master")
|
|
|
|
|
@Example({
|
|
|
|
|
posMasterNoPrefix: "กบ.",
|
|
|
|
|
posMasterNo: 1,
|
|
|
|
|
posMasterNoSuffix: "ช",
|
|
|
|
|
posId: ["08db9e81-fc46-4e95-8b33-be4ca0016abf", "08db9e81-fc46-4e95-8b33-be4ca0016abf"],
|
|
|
|
|
orgRootId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild1Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
positions: [
|
|
|
|
|
{
|
|
|
|
|
posDictName: "นักบริหาร",
|
|
|
|
|
posDictField: "บริหาร",
|
|
|
|
|
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posDictExecutiveField: "นักบริหาร",
|
|
|
|
|
posDictArea: "บริหาร",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
async createMaster(
|
|
|
|
|
@Body()
|
|
|
|
|
requestBody: CreatePosMaster,
|
|
|
|
|
@Request() request: { user: Record<string, any> },
|
|
|
|
|
) {
|
|
|
|
|
const posMaster = Object.assign(new PosMaster(), requestBody);
|
|
|
|
|
if (!posMaster) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 18:24:38 +07:00
|
|
|
let orgRoot: any = null;
|
|
|
|
|
if (requestBody.orgRootId != null)
|
|
|
|
|
orgRoot = await this.orgRootRepository.findOne({
|
|
|
|
|
where: { id: requestBody.orgRootId },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgRoot) {
|
|
|
|
|
let orgChild1: any = null;
|
|
|
|
|
if (requestBody.orgChild1Id != null)
|
|
|
|
|
orgChild1 = await this.child1Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild1Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild1) {
|
|
|
|
|
let orgChild2: any = null;
|
|
|
|
|
if (requestBody.orgChild2Id != null)
|
|
|
|
|
orgChild2 = await this.child2Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild2Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild2) {
|
|
|
|
|
let orgChild3: any = null;
|
|
|
|
|
if (requestBody.orgChild3Id != null)
|
|
|
|
|
orgChild3 = await this.child3Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild3Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild3) {
|
|
|
|
|
let orgChild4: any = null;
|
|
|
|
|
if (requestBody.orgChild4Id != null)
|
|
|
|
|
orgChild4 = await this.child4Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild4Id },
|
|
|
|
|
});
|
2024-01-31 11:00:51 +07:00
|
|
|
if (!orgChild4) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild4.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild4.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild4.orgChild2Id;
|
|
|
|
|
posMaster.orgChild3Id = orgChild4.orgChild3Id;
|
|
|
|
|
posMaster.orgChild4Id = orgChild4.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild4.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild3.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild3.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild3.orgChild2Id;
|
|
|
|
|
posMaster.orgChild3Id = orgChild3.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild3.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild2.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild2.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild2.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild2.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild1.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild1.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild1.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgRoot.id;
|
|
|
|
|
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posMaster.createdUserId = request.user.sub;
|
|
|
|
|
posMaster.createdFullName = request.user.name;
|
|
|
|
|
posMaster.lastUpdateUserId = request.user.sub;
|
|
|
|
|
posMaster.lastUpdateFullName = request.user.name;
|
|
|
|
|
await this.posMasterRepository.save(posMaster);
|
|
|
|
|
|
|
|
|
|
requestBody.positions.forEach(async (x: any) => {
|
|
|
|
|
const position = Object.assign(new Position());
|
|
|
|
|
position.positionName = x.posDictName;
|
|
|
|
|
position.positionField = x.posDictField;
|
|
|
|
|
position.posTypeId = x.posTypeId;
|
|
|
|
|
position.posLevelId = x.posLevelId;
|
|
|
|
|
position.posExecutiveId = x.posExecutiveId;
|
|
|
|
|
position.positionExecutiveField = x.posDictExecutiveField;
|
|
|
|
|
position.positionArea = x.posDictArea;
|
|
|
|
|
position.positionIsSelected = false;
|
|
|
|
|
position.posMasterId = posMaster.id;
|
|
|
|
|
position.createdUserId = request.user.sub;
|
|
|
|
|
position.createdFullName = request.user.name;
|
|
|
|
|
position.lastUpdateUserId = request.user.sub;
|
|
|
|
|
position.lastUpdateFullName = request.user.name;
|
2024-01-31 15:09:22 +07:00
|
|
|
await this.positionRepository.save(position);
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(posMaster.id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API เพิ่มอัตรากำลัง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_033 - เพิ่มอัตรากำลัง (ADMIN) #35
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Put("master/{id}")
|
|
|
|
|
@Example({
|
|
|
|
|
posMasterNoPrefix: "กบ.",
|
2024-01-31 17:20:08 +07:00
|
|
|
posMasterNo: "1",
|
2024-01-31 11:00:51 +07:00
|
|
|
posMasterNoSuffix: "ช",
|
|
|
|
|
posId: ["08db9e81-fc46-4e95-8b33-be4ca0016abf", "08db9e81-fc46-4e95-8b33-be4ca0016abf"],
|
|
|
|
|
orgRootId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild1Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild2Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild3Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
orgChild4Id: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
positions: [
|
|
|
|
|
{
|
|
|
|
|
posDictName: "นักบริหาร",
|
|
|
|
|
posDictField: "บริหาร",
|
|
|
|
|
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
|
|
|
|
posDictExecutiveField: "นักบริหาร",
|
|
|
|
|
posDictArea: "บริหาร",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
async updateMaster(
|
|
|
|
|
@Path() id: string,
|
|
|
|
|
@Body()
|
|
|
|
|
requestBody: CreatePosMaster,
|
|
|
|
|
@Request() request: { user: Record<string, any> },
|
|
|
|
|
) {
|
|
|
|
|
const posMaster = await this.posMasterRepository.findOne({ where: { id: id } });
|
|
|
|
|
if (!posMaster) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
|
|
|
|
|
}
|
2024-01-31 13:24:02 +07:00
|
|
|
posMaster.orgRootId = "";
|
|
|
|
|
posMaster.orgChild1Id = "";
|
|
|
|
|
posMaster.orgChild2Id = "";
|
|
|
|
|
posMaster.orgChild3Id = "";
|
|
|
|
|
posMaster.orgChild4Id = "";
|
2024-01-31 11:00:51 +07:00
|
|
|
|
2024-01-31 18:24:38 +07:00
|
|
|
let orgRoot: any = null;
|
|
|
|
|
if (requestBody.orgRootId != null)
|
|
|
|
|
orgRoot = await this.orgRootRepository.findOne({
|
|
|
|
|
where: { id: requestBody.orgRootId },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgRoot) {
|
|
|
|
|
let orgChild1: any = null;
|
|
|
|
|
if (requestBody.orgChild1Id != null)
|
|
|
|
|
orgChild1 = await this.child1Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild1Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild1) {
|
|
|
|
|
let orgChild2: any = null;
|
|
|
|
|
if (requestBody.orgChild2Id != null)
|
|
|
|
|
orgChild2 = await this.child2Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild2Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild2) {
|
|
|
|
|
let orgChild3: any = null;
|
|
|
|
|
if (requestBody.orgChild3Id != null)
|
|
|
|
|
orgChild3 = await this.child3Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild3Id },
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!orgChild3) {
|
|
|
|
|
let orgChild4: any = null;
|
|
|
|
|
if (requestBody.orgChild4Id != null)
|
|
|
|
|
orgChild4 = await this.child4Repository.findOne({
|
|
|
|
|
where: { id: requestBody.orgChild4Id },
|
|
|
|
|
});
|
2024-01-31 11:00:51 +07:00
|
|
|
if (!orgChild4) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild4.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild4.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild4.orgChild2Id;
|
|
|
|
|
posMaster.orgChild3Id = orgChild4.orgChild3Id;
|
|
|
|
|
posMaster.orgChild4Id = orgChild4.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild4.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild3.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild3.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild3.orgChild2Id;
|
|
|
|
|
posMaster.orgChild3Id = orgChild3.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild3.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild2.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild2.orgChild1Id;
|
|
|
|
|
posMaster.orgChild2Id = orgChild2.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild2.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgChild1.orgRootId;
|
|
|
|
|
posMaster.orgChild1Id = orgChild1.id;
|
|
|
|
|
posMaster.orgRevisionId = orgChild1.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
posMaster.orgRootId = orgRoot.id;
|
|
|
|
|
posMaster.orgRevisionId = orgRoot.orgRevisionId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
posMaster.createdUserId = request.user.sub;
|
|
|
|
|
posMaster.createdFullName = request.user.name;
|
|
|
|
|
posMaster.lastUpdateUserId = request.user.sub;
|
|
|
|
|
posMaster.lastUpdateFullName = request.user.name;
|
|
|
|
|
await this.posMasterRepository.save(posMaster);
|
|
|
|
|
|
2024-01-31 15:09:22 +07:00
|
|
|
await this.positionRepository.delete({ posMasterId: posMaster.id });
|
2024-01-31 11:00:51 +07:00
|
|
|
requestBody.positions.forEach(async (x: any) => {
|
|
|
|
|
const position = Object.assign(new Position());
|
|
|
|
|
position.positionName = x.posDictName;
|
|
|
|
|
position.positionField = x.posDictField;
|
|
|
|
|
position.posTypeId = x.posTypeId;
|
|
|
|
|
position.posLevelId = x.posLevelId;
|
|
|
|
|
position.posExecutiveId = x.posExecutiveId;
|
|
|
|
|
position.positionExecutiveField = x.posDictExecutiveField;
|
|
|
|
|
position.positionArea = x.posDictArea;
|
|
|
|
|
position.positionIsSelected = false;
|
|
|
|
|
position.posMasterId = posMaster.id;
|
|
|
|
|
position.createdUserId = request.user.sub;
|
|
|
|
|
position.createdFullName = request.user.name;
|
|
|
|
|
position.lastUpdateUserId = request.user.sub;
|
|
|
|
|
position.lastUpdateFullName = request.user.name;
|
2024-01-31 15:09:22 +07:00
|
|
|
await this.positionRepository.save(position);
|
2024-01-31 11:00:51 +07:00
|
|
|
});
|
|
|
|
|
return new HttpSuccess(posMaster.id);
|
|
|
|
|
}
|
2024-01-31 14:29:39 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API รายละเอียดอัตรากำลัง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_037 - รายละเอียดอัตรากำลัง (ADMIN) #36
|
|
|
|
|
*
|
|
|
|
|
*/
|
2024-01-31 16:11:49 +07:00
|
|
|
@Get("position/{id}")
|
2024-01-31 16:12:07 +07:00
|
|
|
async detailPosition(@Path() id: string) {
|
2024-01-31 14:29:39 +07:00
|
|
|
try {
|
|
|
|
|
const posMaster = await this.posMasterRepository.findOne({
|
|
|
|
|
where: { id },
|
|
|
|
|
relations: ["posType", "posLevel", "posExecutive"],
|
|
|
|
|
});
|
|
|
|
|
if (!posMaster) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
2024-01-31 15:09:22 +07:00
|
|
|
const positions = await this.positionRepository.find({
|
2024-01-31 14:29:39 +07:00
|
|
|
where: { posMasterId: posMaster.id },
|
|
|
|
|
});
|
|
|
|
|
const formattedData = {
|
|
|
|
|
id: posMaster.id,
|
|
|
|
|
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
|
|
|
|
posMasterNo: posMaster.posMasterNo,
|
|
|
|
|
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
|
|
|
|
positions: positions.map((position) => ({
|
|
|
|
|
id: position.id,
|
|
|
|
|
positionName: position.positionName,
|
|
|
|
|
positionField: position.positionField,
|
|
|
|
|
posTypeId: position.posTypeId,
|
|
|
|
|
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
|
|
|
|
posLevelId: position.posLevelId,
|
|
|
|
|
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
|
|
|
|
posExecutiveId: position.posExecutiveId,
|
|
|
|
|
posExecutiveName:
|
|
|
|
|
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
|
|
|
|
positionExecutiveField: position.positionExecutiveField,
|
|
|
|
|
positionArea: position.positionArea,
|
|
|
|
|
positionIsSelected: position.positionIsSelected,
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
return new HttpSuccess(formattedData);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-31 15:09:22 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API ลบอัตรากำลัง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_035 - ลบอัตรากำลัง (ADMIN) #38
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id Id ตำแหน่ง
|
|
|
|
|
*/
|
|
|
|
|
@Delete("master/{id}")
|
|
|
|
|
async deletePosMaster(@Path() id: string) {
|
|
|
|
|
const delPosMaster = await this.posMasterRepository.findOne({
|
|
|
|
|
where: { id },
|
|
|
|
|
// relations: ["position"],
|
|
|
|
|
});
|
|
|
|
|
if (!delPosMaster) {
|
|
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
await this.positionRepository.delete({ posMasterId: id });
|
|
|
|
|
await this.posMasterRepository.delete({ id });
|
|
|
|
|
return new HttpSuccess();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-31 17:22:45 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API รายการอัตรากำลัง
|
|
|
|
|
*
|
|
|
|
|
* @summary ORG_053 - รายการอัตรากำลัง (ADMIN) #56
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Post("master/list")
|
|
|
|
|
async list(
|
|
|
|
|
@Body()
|
|
|
|
|
body: {
|
|
|
|
|
id: string;
|
|
|
|
|
type: number;
|
2024-01-31 17:51:49 +07:00
|
|
|
isAll: boolean;
|
|
|
|
|
page: number;
|
|
|
|
|
pageSize: number;
|
|
|
|
|
keyword?: string;
|
2024-01-31 17:22:45 +07:00
|
|
|
},
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
let typeCondition: any = {};
|
2024-02-01 11:12:44 +07:00
|
|
|
let checkChildConditions: any = {};
|
2024-01-31 17:22:45 +07:00
|
|
|
|
|
|
|
|
if (body.type === 0) {
|
|
|
|
|
typeCondition = {
|
|
|
|
|
orgRootId: body.id,
|
|
|
|
|
};
|
2024-02-01 11:12:44 +07:00
|
|
|
if (!body.isAll) {
|
|
|
|
|
checkChildConditions = {
|
|
|
|
|
orgChild1Id: IsNull(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-01-31 17:22:45 +07:00
|
|
|
} else if (body.type === 1) {
|
|
|
|
|
typeCondition = {
|
|
|
|
|
orgChild1Id: body.id,
|
|
|
|
|
};
|
2024-02-01 11:12:44 +07:00
|
|
|
if (!body.isAll) {
|
|
|
|
|
checkChildConditions = {
|
|
|
|
|
orgChild2Id: IsNull(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-01-31 17:22:45 +07:00
|
|
|
} else if (body.type === 2) {
|
|
|
|
|
typeCondition = {
|
|
|
|
|
orgChild2Id: body.id,
|
|
|
|
|
};
|
2024-02-01 11:12:44 +07:00
|
|
|
if (!body.isAll) {
|
|
|
|
|
checkChildConditions = {
|
|
|
|
|
orgChild3Id: IsNull(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-01-31 17:22:45 +07:00
|
|
|
} else if (body.type === 3) {
|
|
|
|
|
typeCondition = {
|
|
|
|
|
orgChild3Id: body.id,
|
|
|
|
|
};
|
2024-02-01 11:12:44 +07:00
|
|
|
if (!body.isAll) {
|
|
|
|
|
checkChildConditions = {
|
|
|
|
|
orgChild4Id: IsNull(),
|
|
|
|
|
};
|
|
|
|
|
}
|
2024-01-31 17:22:45 +07:00
|
|
|
} else if (body.type === 4) {
|
|
|
|
|
typeCondition = {
|
|
|
|
|
orgChild4Id: body.id,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const posMaster = await this.posMasterRepository.find({
|
2024-02-01 11:12:44 +07:00
|
|
|
where: {
|
|
|
|
|
...typeCondition,
|
|
|
|
|
...checkChildConditions,
|
|
|
|
|
},
|
2024-01-31 17:22:45 +07:00
|
|
|
});
|
2024-01-31 18:24:38 +07:00
|
|
|
if (!posMaster || posMaster.length === 0) {
|
2024-01-31 17:51:49 +07:00
|
|
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
|
|
|
|
}
|
2024-01-31 18:24:38 +07:00
|
|
|
const formattedData = await Promise.all(
|
|
|
|
|
posMaster.map(async (posMaster) => {
|
|
|
|
|
const positions = await this.positionRepository.find({
|
|
|
|
|
where: { posMasterId: posMaster.id },
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
id: posMaster.id,
|
|
|
|
|
posMasterNoPrefix: posMaster.posMasterNoPrefix,
|
|
|
|
|
posMasterNo: posMaster.posMasterNo,
|
|
|
|
|
posMasterNoSuffix: posMaster.posMasterNoSuffix,
|
|
|
|
|
positions: positions.map((position) => ({
|
|
|
|
|
id: position.id,
|
|
|
|
|
positionName: position.positionName,
|
|
|
|
|
positionField: position.positionField,
|
|
|
|
|
posTypeId: position.posTypeId,
|
|
|
|
|
posTypeName: position.posType == null ? null : position.posType.posTypeName,
|
|
|
|
|
posLevelId: position.posLevelId,
|
|
|
|
|
posLevelName: position.posLevel == null ? null : position.posLevel.posLevelName,
|
|
|
|
|
posExecutiveId: position.posExecutiveId,
|
|
|
|
|
posExecutiveName:
|
|
|
|
|
position.posExecutive == null ? null : position.posExecutive.posExecutiveName,
|
|
|
|
|
positionExecutiveField: position.positionExecutiveField,
|
|
|
|
|
positionArea: position.positionArea,
|
|
|
|
|
positionIsSelected: position.positionIsSelected,
|
|
|
|
|
})),
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
);
|
2024-01-31 17:51:49 +07:00
|
|
|
return new HttpSuccess(formattedData);
|
2024-01-31 17:22:45 +07:00
|
|
|
} catch (error) {
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-30 15:10:11 +07:00
|
|
|
}
|