Merge branch 'develop' into adiDev
This commit is contained in:
commit
763bc5e372
3 changed files with 238 additions and 5 deletions
|
|
@ -1663,4 +1663,188 @@ export class OrganizationController extends Controller {
|
|||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API Organizational StructChart
|
||||
*
|
||||
* @summary Organizational StructChart
|
||||
*
|
||||
*/
|
||||
@Get("struct-chart/{idNode}/{type}")//bright
|
||||
async structchart(@Path() idNode: string, type: number) {
|
||||
try {
|
||||
|
||||
let revision: any;
|
||||
let root: any;
|
||||
let child1: any;
|
||||
let child2: any;
|
||||
let child3: any;
|
||||
let child4: any;
|
||||
let totalPositionCount_1: any;
|
||||
let totalPositionVacant_1: any;
|
||||
let totalPositionCount_2: any;
|
||||
let totalPositionVacant_2: any;
|
||||
let totalPositionCount_3: any;
|
||||
let totalPositionVacant_3: any;
|
||||
let totalPositionCount_4: any;
|
||||
let totalPositionVacant_4: any;
|
||||
let totalPositionCount_5: any;
|
||||
let totalPositionVacant_5: any;
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
|
||||
revision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!revision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found revision");
|
||||
}
|
||||
totalPositionCount_1 = await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: idNode
|
||||
}
|
||||
});
|
||||
totalPositionVacant_1 = await this.posMasterRepository.count({
|
||||
where: {
|
||||
orgRevisionId: idNode,
|
||||
current_holderId: IsNull() && "",
|
||||
}
|
||||
});
|
||||
root = await this.orgRootRepository.find({
|
||||
where: {
|
||||
orgRevisionId: idNode
|
||||
},
|
||||
});
|
||||
|
||||
if(root.length > 0){
|
||||
child1 = await this.child1Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
orgRootId: root.id,
|
||||
},
|
||||
});
|
||||
if(child1.length > 0){
|
||||
child2 = await this.child2Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
orgChild1Id: child1.id
|
||||
},
|
||||
});
|
||||
if(child2.length > 0){
|
||||
child3 = await this.child3Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
// orgChild1Id: child1.id,
|
||||
orgChild2Id: child2.id
|
||||
},
|
||||
});
|
||||
if(child3.length > 0){
|
||||
child4 = await this.child4Repository.find({
|
||||
where: {
|
||||
// orgRevisionId: idNode,
|
||||
// orgRootId: root.id,
|
||||
// orgChild1Id: child1.id,
|
||||
// orgChild2Id: child2.id,
|
||||
orgChild3Id: child3.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Tree
|
||||
const treeObject = {
|
||||
deptID: revision.id,
|
||||
departmentName: revision.orgRevisionName,
|
||||
totalPositionCount: totalPositionCount_1 == 0 || null ? 0 : totalPositionCount_1,
|
||||
totalPositionVacant: totalPositionVacant_1 == 0 || null ? 0 : totalPositionVacant_1,
|
||||
children: root.map((roots:any) => ({
|
||||
deptID: roots.id,
|
||||
departmentName: roots.orgRootName,
|
||||
|
||||
|
||||
})),
|
||||
heads: [
|
||||
{
|
||||
positionID: null,
|
||||
positionName: null,
|
||||
positionNum: null,
|
||||
totalPositionCount: 0,
|
||||
totalPositionVacant: 0
|
||||
}
|
||||
],
|
||||
officer: [
|
||||
{
|
||||
positionID: null,
|
||||
positionName: null,
|
||||
positionNum: null,
|
||||
totalPositionCount: 0,
|
||||
totalPositionVacant: 0
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
return new HttpSuccess(treeObject)
|
||||
|
||||
}
|
||||
case 1: {
|
||||
root = await this.orgRootRepository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!root) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found rootId");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
child1 = await this.child1Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child1) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child1Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
child2 = await this.child2Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child2Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
child3 = await this.child3Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child3Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
child4 = await this.child4Repository.findOne({
|
||||
where: { id: idNode },
|
||||
});
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found child4Id");
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found type: ");
|
||||
}
|
||||
|
||||
// return new HttpSuccess();
|
||||
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,55 @@ 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 + " มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
try {
|
||||
posDict.createdUserId = request.user.sub;
|
||||
posDict.createdFullName = request.user.name;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue