Merge branch 'develop' into adiDev

# Conflicts:
#	src/controllers/PositionController.ts
This commit is contained in:
AdisakKanthawilang 2024-02-15 13:10:25 +07:00
commit 14bc29b675
2 changed files with 82 additions and 74 deletions

View file

@ -33,7 +33,7 @@ import { log } from "console";
@Route("api/v1/org")
@Tags("Organization")
// @Security("bearerAuth")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
@ -1690,8 +1690,9 @@ export class OrganizationController extends Controller {
}
const formattedData = {
departmentName: "กรุงเทพมหานคร",
departmentName: data.orgRevisionName,
deptID: data.id,
type: 0,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRevisionId: data.id },
@ -1729,6 +1730,7 @@ export class OrganizationController extends Controller {
return {
departmentName: orgRoot.orgRootName,
deptID: orgRoot.id,
type: 1,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRevisionId: data.id, orgRootId: orgRoot.id },
@ -1769,6 +1771,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild1) => ({
departmentName: orgChild1.orgChild1Name,
deptID: orgChild1.id,
type: 2,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -1817,6 +1820,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -1870,6 +1874,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -1929,9 +1934,9 @@ export class OrganizationController extends Controller {
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount:
await this.posMasterRepository.count({
@ -2004,7 +2009,7 @@ export class OrganizationController extends Controller {
}),
),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
case 1: {
const data = await this.orgRootRepository.findOne({
@ -2024,6 +2029,7 @@ export class OrganizationController extends Controller {
const formattedData = {
departmentName: data.orgRootName,
deptID: data.id,
type: 1,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRootId: data.id },
@ -2061,6 +2067,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild1) => ({
departmentName: orgChild1.orgChild1Name,
deptID: orgChild1.id,
type: 2,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRootId: data.id, orgChild1Id: orgChild1.id },
@ -2101,6 +2108,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2149,6 +2157,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2200,9 +2209,9 @@ export class OrganizationController extends Controller {
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2265,7 +2274,7 @@ export class OrganizationController extends Controller {
})),
),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
case 2: {
const data = await this.child1Repository.findOne({
@ -2284,6 +2293,7 @@ export class OrganizationController extends Controller {
const formattedData = {
departmentName: data.orgChild1Name,
deptID: data.id,
type: 2,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgRevisionId: data.id },
@ -2321,6 +2331,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild2) => ({
departmentName: orgChild2.orgChild2Name,
deptID: orgChild2.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild1Id: data.id, orgChild2Id: orgChild2.id },
@ -2361,6 +2372,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2407,9 +2419,9 @@ export class OrganizationController extends Controller {
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2464,7 +2476,7 @@ export class OrganizationController extends Controller {
})),
),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
case 3: {
const data = await this.child2Repository.findOne({
@ -2478,6 +2490,7 @@ export class OrganizationController extends Controller {
const formattedData = {
departmentName: data.orgChild2Name,
deptID: data.id,
type: 3,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild2Id: data.id },
@ -2515,6 +2528,7 @@ export class OrganizationController extends Controller {
.map(async (orgChild3) => ({
departmentName: orgChild3.orgChild3Name,
deptID: orgChild3.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild2Id: data.id, orgChild3Id: orgChild3.id },
@ -2553,9 +2567,9 @@ export class OrganizationController extends Controller {
orgChild3.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: {
@ -2603,7 +2617,7 @@ export class OrganizationController extends Controller {
})),
),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
case 4: {
const data = await this.child3Repository.findOne({
@ -2615,9 +2629,9 @@ export class OrganizationController extends Controller {
}
const formattedData = {
orgTreeId: data.id,
departmentName: data.orgChild3Name,
deptID: data.id,
type: 4,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild3Id: data.id },
@ -2653,9 +2667,9 @@ export class OrganizationController extends Controller {
data.orgChild4s
.sort((a, b) => a.orgChild4Order - b.orgChild4Order)
.map(async (orgChild4) => ({
orgTreeId: orgChild4.id,
departmentName: orgChild4.orgChild4Name,
deptID: orgChild4.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild3Id: data.id, orgChild4Id: orgChild4.id },
@ -2693,7 +2707,7 @@ export class OrganizationController extends Controller {
})),
),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
case 5: {
const data = await this.child4Repository.findOne({
@ -2705,9 +2719,9 @@ export class OrganizationController extends Controller {
}
const formattedData = {
orgTreeId: data.id,
departmentName: data.orgChild4Name,
deptID: data.id,
type: 5,
// heads:
totalPositionCount: await this.posMasterRepository.count({
where: { orgChild4Id: data.id },
@ -2739,7 +2753,7 @@ export class OrganizationController extends Controller {
// },
// }),
};
return new HttpSuccess(formattedData);
return new HttpSuccess([formattedData]);
}
default:
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: ");

View file

@ -24,7 +24,7 @@ import { PosType } from "../entities/PosType";
import { PosLevel } from "../entities/PosLevel";
import { CreatePosDict, PosDict } from "../entities/PosDict";
import HttpError from "../interfaces/http-error";
import { Equal, ILike, In, IsNull, Like, Not ,Brackets } from "typeorm";
import { Equal, ILike, In, IsNull, Like, Not, Brackets } from "typeorm";
import { CreatePosMaster, PosMaster } from "../entities/PosMaster";
import { OrgRevision } from "../entities/OrgRevision";
import { OrgRoot } from "../entities/OrgRoot";
@ -33,9 +33,10 @@ import { OrgChild2 } from "../entities/OrgChild2";
import { OrgChild3 } from "../entities/OrgChild3";
import { OrgChild4 } from "../entities/OrgChild4";
import { Position } from "../entities/Position";
import { Profile } from "../entities/Profile";
@Route("api/v1/org/pos")
@Tags("Position")
// @Security("bearerAuth")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
@ -48,7 +49,7 @@ export class PositionController extends Controller {
private posDictRepository = AppDataSource.getRepository(PosDict);
private posMasterRepository = AppDataSource.getRepository(PosMaster);
private positionRepository = AppDataSource.getRepository(Position);
private profileRepository = AppDataSource.getRepository(Profile);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private child1Repository = AppDataSource.getRepository(OrgChild1);
@ -111,53 +112,19 @@ export class PositionController extends Controller {
}
}
const chk_posDictName = await this.posDictRepository.findOne({
where: { posDictName: posDict.posDictName }
})
if(chk_posDictName){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งในสายงาน: " + chk_posDictName.posDictName + " มีอยู่ในระบบแล้ว");
}
const chk_posDictField = await this.posDictRepository.findOne({
where: { posDictField: posDict.posDictField }
})
if(chk_posDictField){
throw new HttpError(HttpStatusCode.NOT_FOUND, "สายงาน: " + chk_posDictField.posDictField + " มีอยู่ในระบบแล้ว");
}
const chk_posTypeId = await this.posDictRepository.findOne({
where: { posTypeId: posDict.posTypeId }
})
if(chk_posTypeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งประเภท: " + chk_posTypeId.posTypeId + " มีอยู่ในระบบแล้ว");
}
const chk_posLevelId = await this.posDictRepository.findOne({
where: { posLevelId: posDict.posLevelId }
})
if(chk_posLevelId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ระดับตำแหน่ง: " + chk_posLevelId.posLevelId + " มีอยู่ในระบบแล้ว");
}
const chk_posExecutiveId = await this.posDictRepository.findOne({
where: { posExecutiveId: String(posDict.posExecutiveId) }
})
if(chk_posExecutiveId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ตำแหน่งทางการบริหาร: " + chk_posExecutiveId.posExecutiveId + " มีอยู่ในระบบแล้ว");
}
const chk_posDictExecutiveField = await this.posDictRepository.findOne({
where: { posDictExecutiveField: posDict.posDictExecutiveField }
})
if(chk_posDictExecutiveField){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้านทางการบริหาร: " + chk_posDictExecutiveField.posDictExecutiveField + " มีอยู่ในระบบแล้ว");
}
const chk_posDictArea= await this.posDictRepository.findOne({
where: { posDictArea: posDict.posDictArea }
})
if(chk_posDictArea){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ด้าน/สาขา: " + chk_posDictArea.posDictArea + " มีอยู่ในระบบแล้ว");
const rowRepeated = await this.posDictRepository.findOne({
where: {
posDictName: posDict.posDictName,
posDictField: posDict.posDictField,
posTypeId: posDict.posTypeId,
posLevelId: posDict.posLevelId,
posExecutiveId: String(posDict.posExecutiveId),
posDictExecutiveField: posDict.posDictExecutiveField,
posDictArea: posDict.posDictArea,
},
});
if (rowRepeated) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ข้อมูล Row นี้มีอยู่ในระบบแล้ว");
}
try {
@ -650,6 +617,7 @@ export class PositionController extends Controller {
const positions = await this.positionRepository.find({
where: { posMasterId: posMaster.id },
relations: ["posType", "posLevel", "posExecutive"],
order: { lastUpdatedAt: "ASC" },
});
const formattedData = {
id: posMaster.id,
@ -808,19 +776,17 @@ export class PositionController extends Controller {
}
masterId = [...new Set(masterId)];
}
const conditions = [
{
...checkChildConditions,
...typeCondition,
...(body.keyword && (
masterId.length > 0
? { id: In(masterId)}
: { posMasterNo: Like(`%${body.keyword}%`) }
)),
...(body.keyword &&
(masterId.length > 0
? { id: In(masterId) }
: { posMasterNo: Like(`%${body.keyword}%`) })),
},
]
];
// if (body.keyword) {
// conditions.push({
@ -831,7 +797,7 @@ export class PositionController extends Controller {
// const [posMaster, total] = await this.posMasterRepository.findAndCount({
// where: conditions,
// order: { posMasterOrder: "ASC" },
// order: { posMasterOrder: "ASC" },
// relations: [
// "orgRoot",
// "orgChild1",
@ -887,6 +853,27 @@ export class PositionController extends Controller {
relations: ["posLevel", "posType", "posExecutive"],
});
let profile: any;
const chkRevision = await this.orgRevisionRepository.findOne({
where: { id: posMaster.orgRevisionId }
})
if(chkRevision?.orgRevisionIsCurrent && !chkRevision?.orgRevisionIsDraft){
profile = await this.profileRepository.findOne({
where: { id: String(posMaster.current_holderId) },
});
}
else if(!chkRevision?.orgRevisionIsCurrent && chkRevision?.orgRevisionIsDraft){
profile = await this.profileRepository.findOne({
where: { id: String(posMaster.next_holderId) },
});
}
const type = await this.posTypeRepository.findOne({
where: { id: String(profile?.posTypeId) },
});
const level = await this.posLevelRepository.findOne({
where: { id: String(profile?.posLevelId) },
});
let shortName = "";
// if (body.isAll === true) {
@ -952,6 +939,13 @@ export class PositionController extends Controller {
? null
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
orgShortname: shortName,
isSit: posMaster.isSit,
profilePosition:
profile == null || profile.position == null ? null : profile.position,
profilePostype:
type == null || type.posTypeName == null ? null : type.posTypeName,
profilePoslevel:
level == null || level.posLevelName == null ? null : level.posLevelName,
positions: positions.map((position) => ({
id: position.id,
positionName: position.positionName,