api ผังโครงสร้ารายบุคคล (ค้างตำแหน่ง)
This commit is contained in:
parent
0db2af5c78
commit
59359d2915
1 changed files with 264 additions and 0 deletions
|
|
@ -1750,6 +1750,270 @@ export class OrganizationController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API Organizational Chart
|
||||
*
|
||||
* @summary Organizational Chart
|
||||
*
|
||||
* @param {string} revisionId Id revison
|
||||
*/
|
||||
@Get("org-chart/{revisionId}")
|
||||
async orgchart(@Path() revisionId: string) {
|
||||
|
||||
const data = await this.orgRevisionRepository.findOne({
|
||||
where: { id: revisionId }
|
||||
});
|
||||
if (!data) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||
}
|
||||
let posMasterRoot:any;
|
||||
let posMasterChild1:any;
|
||||
let posMasterChild2:any;
|
||||
let posMasterChild3:any;
|
||||
let posMasterChild4:any;
|
||||
if(data.orgRevisionIsCurrent == true && data.orgRevisionIsDraft == false) {
|
||||
posMasterRoot = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild1Id: IsNull(),
|
||||
current_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["current_holder", "orgRoot",]
|
||||
});
|
||||
posMasterChild1 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild2Id: IsNull(),
|
||||
orgChild1Id: Not(IsNull()),
|
||||
current_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["current_holder", "orgChild1"]
|
||||
});
|
||||
posMasterChild2 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild3Id: IsNull(),
|
||||
orgChild2Id: Not(IsNull()),
|
||||
current_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["current_holder", "orgChild2"]
|
||||
});
|
||||
posMasterChild3 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild4Id: IsNull(),
|
||||
orgChild3Id: Not(IsNull()),
|
||||
current_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["current_holder", "orgChild3"]
|
||||
});
|
||||
posMasterChild4 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild4Id: Not(IsNull()),
|
||||
current_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["current_holder", "orgChild4"]
|
||||
});
|
||||
|
||||
let formattedData = posMasterRoot
|
||||
.filter((x:any) => x.current_holderId !=null)
|
||||
.map((x0:PosMaster) => ({
|
||||
personID: x0.current_holder.id,
|
||||
name: x0.current_holder.firstName,
|
||||
avatar: x0.current_holder.avatar,
|
||||
positionName: /*this.positionRepository.findOne({
|
||||
where: { id: x1.id },select:["positionName"]
|
||||
})*/"",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x0.orgRoot.orgRootName,
|
||||
organizationId: x0.orgRoot.id,
|
||||
children: posMasterChild1
|
||||
.filter((x:any) => x.current_holderId !=null && x.orgRootId == x0.orgRootId)
|
||||
.map((x1:PosMaster) =>({
|
||||
personID: x1.current_holder.id,
|
||||
name: x1.current_holder.firstName,
|
||||
avatar: x1.current_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x1.orgChild1.orgChild1Name,
|
||||
organizationId: x1.orgChild1.id,
|
||||
children: posMasterChild2
|
||||
.filter((x:any) => x.current_holderId !=null && x.child1Id == x1.orgChild1Id)
|
||||
.map((x2:PosMaster) =>({
|
||||
personID: x2.current_holder.id,
|
||||
name: x2.current_holder.firstName,
|
||||
avatar: x2.current_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x2.orgChild2.orgChild2Name,
|
||||
organizationId: x2.orgChild2.id,
|
||||
children: posMasterChild3
|
||||
.filter((x:any) => x.current_holderId !=null && x.child2Id == x2.orgChild2Id)
|
||||
.map((x3:PosMaster) =>({
|
||||
personID: x3.current_holder.id,
|
||||
name: x3.current_holder.firstName,
|
||||
avatar: x3.current_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x3.orgChild3.orgChild3Name,
|
||||
organizationId: x3.orgChild3.id,
|
||||
children: posMasterChild4
|
||||
.filter((x:any) => x.current_holderId !=null && x.child3Id == x3.orgChild3Id)
|
||||
.map((x4:PosMaster) =>({
|
||||
personID: x4.current_holder.id,
|
||||
name: x4.current_holder.firstName,
|
||||
avatar: x4.current_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x4.orgChild4.orgChild4Name,
|
||||
organizationId: x4.orgChild4.id,
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}));
|
||||
|
||||
const formattedData_ = {
|
||||
personID: "",
|
||||
name: "",
|
||||
avatar: "",
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: data.orgRevisionName,
|
||||
organizationId: data.id,
|
||||
children: formattedData
|
||||
};
|
||||
return new HttpSuccess([formattedData_]);
|
||||
|
||||
}
|
||||
else if(data.orgRevisionIsCurrent == false && data.orgRevisionIsDraft == true) {
|
||||
posMasterRoot = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild1Id: IsNull(),
|
||||
next_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["next_holder", "orgRoot"]
|
||||
});
|
||||
posMasterChild1 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild2Id: IsNull(),
|
||||
orgChild1Id: Not(IsNull()),
|
||||
next_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["next_holder", "orgChild1"]
|
||||
});
|
||||
posMasterChild2 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild3Id: IsNull(),
|
||||
orgChild2Id: Not(IsNull()),
|
||||
next_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["next_holder", "orgChild2"]
|
||||
});
|
||||
posMasterChild3 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild4Id: IsNull(),
|
||||
orgChild3Id: Not(IsNull()),
|
||||
next_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["next_holder", "orgChild3"]
|
||||
});
|
||||
posMasterChild4 = await this.posMasterRepository.find({
|
||||
where: {
|
||||
orgRevisionId: data.id,
|
||||
orgChild4Id: Not(IsNull()),
|
||||
next_holderId: Not(IsNull())
|
||||
},
|
||||
relations:["next_holder", "orgChild4"]
|
||||
});
|
||||
|
||||
let formattedData = posMasterRoot
|
||||
.filter((x:any) => x.next_holderId !=null)
|
||||
.map((x0:PosMaster) => ({
|
||||
personID: x0.next_holder.id,
|
||||
name: x0.next_holder.firstName,
|
||||
avatar: x0.next_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x0.orgRoot.orgRootName,
|
||||
organizationId: x0.orgRoot.id,
|
||||
children: posMasterChild1
|
||||
.filter((x:any) => x.next_holderId !=null && x.orgRootId == x0.orgRootId)
|
||||
.map((x1:PosMaster)=>({
|
||||
personID: x1.next_holder.id,
|
||||
name: x1.next_holder.firstName,
|
||||
avatar: x1.next_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x1.orgChild1.orgChild1Name,
|
||||
organizationId: x1.orgChild1.id,
|
||||
children: posMasterChild2
|
||||
.filter((x:any) => x.next_holderId !=null && x.child1Id == x1.orgChild1Id)
|
||||
.map((x2:PosMaster) =>({
|
||||
personID: x2.next_holder.id,
|
||||
name: x2.next_holder.firstName,
|
||||
avatar: x2.next_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x2.orgChild2.orgChild2Name,
|
||||
organizationId: x2.orgChild2.id,
|
||||
children: posMasterChild3
|
||||
.filter((x:any) => x.next_holderId !=null && x.child2Id == x2.orgChild2Id)
|
||||
.map((x3:PosMaster) =>({
|
||||
personID: x3.next_holder.id,
|
||||
name: x3.next_holder.firstName,
|
||||
avatar: x3.next_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x3.orgChild3.orgChild3Name,
|
||||
organizationId: x3.orgChild3.id,
|
||||
children: posMasterChild4
|
||||
.filter((x:any) => x.next_holderId !=null && x.child3Id == x3.orgChild3Id)
|
||||
.map((x4:PosMaster) =>({
|
||||
personID: x4.next_holder.id,
|
||||
name: x4.next_holder.firstName,
|
||||
avatar: x4.next_holder.avatar,
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: x4.orgChild4.orgChild4Name,
|
||||
organizationId: x4.orgChild4.id,
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}))
|
||||
}));
|
||||
|
||||
const formattedData_ = {
|
||||
personID: "",
|
||||
name: "",
|
||||
avatar: "",
|
||||
positionName: "",
|
||||
positionNum: "",
|
||||
positionNumInt: null,
|
||||
departmentName: data.orgRevisionName,
|
||||
organizationId: data.id,
|
||||
children: formattedData
|
||||
};
|
||||
return new HttpSuccess([formattedData_]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API Organizational StructChart
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue