แก้ค้นหาคนในโครงสร้าง
This commit is contained in:
parent
12885adf17
commit
3170b1ccf9
2 changed files with 217 additions and 161 deletions
|
|
@ -1759,124 +1759,125 @@ export class OrganizationController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Get("org-chart/{revisionId}")
|
@Get("org-chart/{revisionId}")
|
||||||
async orgchart(@Path() revisionId: string) {
|
async orgchart(@Path() revisionId: string) {
|
||||||
|
|
||||||
const data = await this.orgRevisionRepository.findOne({
|
const data = await this.orgRevisionRepository.findOne({
|
||||||
where: { id: revisionId }
|
where: { id: revisionId },
|
||||||
});
|
});
|
||||||
if (!data) {
|
if (!data) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงสร้าง");
|
||||||
}
|
}
|
||||||
let posMasterRoot:any;
|
let posMasterRoot: any;
|
||||||
let posMasterChild1:any;
|
let posMasterChild1: any;
|
||||||
let posMasterChild2:any;
|
let posMasterChild2: any;
|
||||||
let posMasterChild3:any;
|
let posMasterChild3: any;
|
||||||
let posMasterChild4:any;
|
let posMasterChild4: any;
|
||||||
if(data.orgRevisionIsCurrent == true && data.orgRevisionIsDraft == false) {
|
if (data.orgRevisionIsCurrent == true && data.orgRevisionIsDraft == false) {
|
||||||
posMasterRoot = await this.posMasterRepository.find({
|
posMasterRoot = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild1Id: IsNull(),
|
orgChild1Id: IsNull(),
|
||||||
current_holderId: Not(IsNull())
|
current_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["current_holder", "orgRoot",]
|
relations: ["current_holder", "orgRoot"],
|
||||||
});
|
});
|
||||||
posMasterChild1 = await this.posMasterRepository.find({
|
posMasterChild1 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild2Id: IsNull(),
|
orgChild2Id: IsNull(),
|
||||||
orgChild1Id: Not(IsNull()),
|
orgChild1Id: Not(IsNull()),
|
||||||
current_holderId: Not(IsNull())
|
current_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["current_holder", "orgChild1"]
|
relations: ["current_holder", "orgChild1"],
|
||||||
});
|
});
|
||||||
posMasterChild2 = await this.posMasterRepository.find({
|
posMasterChild2 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild3Id: IsNull(),
|
orgChild3Id: IsNull(),
|
||||||
orgChild2Id: Not(IsNull()),
|
orgChild2Id: Not(IsNull()),
|
||||||
current_holderId: Not(IsNull())
|
current_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["current_holder", "orgChild2"]
|
relations: ["current_holder", "orgChild2"],
|
||||||
});
|
});
|
||||||
posMasterChild3 = await this.posMasterRepository.find({
|
posMasterChild3 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild4Id: IsNull(),
|
orgChild4Id: IsNull(),
|
||||||
orgChild3Id: Not(IsNull()),
|
orgChild3Id: Not(IsNull()),
|
||||||
current_holderId: Not(IsNull())
|
current_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["current_holder", "orgChild3"]
|
relations: ["current_holder", "orgChild3"],
|
||||||
});
|
});
|
||||||
posMasterChild4 = await this.posMasterRepository.find({
|
posMasterChild4 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild4Id: Not(IsNull()),
|
orgChild4Id: Not(IsNull()),
|
||||||
current_holderId: Not(IsNull())
|
current_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["current_holder", "orgChild4"]
|
relations: ["current_holder", "orgChild4"],
|
||||||
});
|
});
|
||||||
|
|
||||||
let formattedData = posMasterRoot
|
let formattedData = posMasterRoot
|
||||||
.filter((x:any) => x.current_holderId !=null)
|
.filter((x: any) => x.current_holderId != null)
|
||||||
.map((x0:PosMaster) => ({
|
.map((x0: PosMaster) => ({
|
||||||
personID: x0.current_holder.id,
|
personID: x0.current_holder.id,
|
||||||
name: x0.current_holder.firstName,
|
name: x0.current_holder.firstName,
|
||||||
avatar: x0.current_holder.avatar,
|
avatar: x0.current_holder.avatar,
|
||||||
positionName: x0.current_holder.position,
|
positionName: x0.current_holder.position,
|
||||||
positionNum: x0.orgRoot.orgRootShortName+x0.posMasterNo,
|
positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo,
|
||||||
positionNumInt: x0.posMasterNo,
|
positionNumInt: x0.posMasterNo,
|
||||||
departmentName: x0.orgRoot.orgRootName,
|
departmentName: x0.orgRoot.orgRootName,
|
||||||
organizationId: x0.orgRoot.id,
|
organizationId: x0.orgRoot.id,
|
||||||
children: posMasterChild1
|
children: posMasterChild1
|
||||||
.filter((x:any) => x.current_holderId !=null && x.orgRootId == x0.orgRootId)
|
.filter((x: any) => x.current_holderId != null && x.orgRootId == x0.orgRootId)
|
||||||
.map((x1:PosMaster) =>({
|
.map((x1: PosMaster) => ({
|
||||||
personID: x1.current_holder.id,
|
personID: x1.current_holder.id,
|
||||||
name: x1.current_holder.firstName,
|
name: x1.current_holder.firstName,
|
||||||
avatar: x1.current_holder.avatar,
|
avatar: x1.current_holder.avatar,
|
||||||
positionName: x1.current_holder.position,
|
positionName: x1.current_holder.position,
|
||||||
positionNum: x1.orgChild1.orgChild1ShortName+x1.posMasterNo,
|
positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo,
|
||||||
positionNumInt: x1.posMasterNo,
|
positionNumInt: x1.posMasterNo,
|
||||||
departmentName: x1.orgChild1.orgChild1Name,
|
departmentName: x1.orgChild1.orgChild1Name,
|
||||||
organizationId: x1.orgChild1.id,
|
organizationId: x1.orgChild1.id,
|
||||||
children: posMasterChild2
|
children: posMasterChild2
|
||||||
.filter((x:any) => x.current_holderId !=null && x.child1Id == x1.orgChild1Id)
|
.filter((x: any) => x.current_holderId != null && x.child1Id == x1.orgChild1Id)
|
||||||
.map((x2:PosMaster) =>({
|
.map((x2: PosMaster) => ({
|
||||||
personID: x2.current_holder.id,
|
personID: x2.current_holder.id,
|
||||||
name: x2.current_holder.firstName,
|
name: x2.current_holder.firstName,
|
||||||
avatar: x2.current_holder.avatar,
|
avatar: x2.current_holder.avatar,
|
||||||
positionName: x2.current_holder.position,
|
positionName: x2.current_holder.position,
|
||||||
positionNum: x2.orgChild2.orgChild2ShortName+x2.posMasterNo,
|
positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo,
|
||||||
positionNumInt: x2.posMasterNo,
|
positionNumInt: x2.posMasterNo,
|
||||||
departmentName: x2.orgChild2.orgChild2Name,
|
departmentName: x2.orgChild2.orgChild2Name,
|
||||||
organizationId: x2.orgChild2.id,
|
organizationId: x2.orgChild2.id,
|
||||||
children: posMasterChild3
|
children: posMasterChild3
|
||||||
.filter((x:any) => x.current_holderId !=null && x.child2Id == x2.orgChild2Id)
|
.filter((x: any) => x.current_holderId != null && x.child2Id == x2.orgChild2Id)
|
||||||
.map((x3:PosMaster) =>({
|
.map((x3: PosMaster) => ({
|
||||||
personID: x3.current_holder.id,
|
personID: x3.current_holder.id,
|
||||||
name: x3.current_holder.firstName,
|
name: x3.current_holder.firstName,
|
||||||
avatar: x3.current_holder.avatar,
|
avatar: x3.current_holder.avatar,
|
||||||
positionName: x3.current_holder.position,
|
positionName: x3.current_holder.position,
|
||||||
positionNum: x3.orgChild3.orgChild3ShortName+x3.posMasterNo,
|
positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo,
|
||||||
positionNumInt: x3.posMasterNo,
|
positionNumInt: x3.posMasterNo,
|
||||||
departmentName: x3.orgChild3.orgChild3Name,
|
departmentName: x3.orgChild3.orgChild3Name,
|
||||||
organizationId: x3.orgChild3.id,
|
organizationId: x3.orgChild3.id,
|
||||||
children: posMasterChild4
|
children: posMasterChild4
|
||||||
.filter((x:any) => x.current_holderId !=null && x.child3Id == x3.orgChild3Id)
|
.filter(
|
||||||
.map((x4:PosMaster) =>({
|
(x: any) => x.current_holderId != null && x.child3Id == x3.orgChild3Id,
|
||||||
personID: x4.current_holder.id,
|
)
|
||||||
name: x4.current_holder.firstName,
|
.map((x4: PosMaster) => ({
|
||||||
avatar: x4.current_holder.avatar,
|
personID: x4.current_holder.id,
|
||||||
positionName: x4.current_holder.position,
|
name: x4.current_holder.firstName,
|
||||||
positionNum: x4.orgChild4.orgChild4ShortName+x4.posMasterNo,
|
avatar: x4.current_holder.avatar,
|
||||||
positionNumInt: x4.posMasterNo,
|
positionName: x4.current_holder.position,
|
||||||
departmentName: x4.orgChild4.orgChild4Name,
|
positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo,
|
||||||
organizationId: x4.orgChild4.id,
|
positionNumInt: x4.posMasterNo,
|
||||||
}))
|
departmentName: x4.orgChild4.orgChild4Name,
|
||||||
}))
|
organizationId: x4.orgChild4.id,
|
||||||
}))
|
})),
|
||||||
}))
|
})),
|
||||||
}));
|
})),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
const formattedData_ = {
|
const formattedData_ = {
|
||||||
personID: "",
|
personID: "",
|
||||||
name: "",
|
name: "",
|
||||||
|
|
@ -1886,117 +1887,115 @@ export class OrganizationController extends Controller {
|
||||||
positionNumInt: null,
|
positionNumInt: null,
|
||||||
departmentName: data.orgRevisionName,
|
departmentName: data.orgRevisionName,
|
||||||
organizationId: data.id,
|
organizationId: data.id,
|
||||||
children: formattedData
|
children: formattedData,
|
||||||
};
|
};
|
||||||
return new HttpSuccess([formattedData_]);
|
return new HttpSuccess([formattedData_]);
|
||||||
|
} else if (data.orgRevisionIsCurrent == false && data.orgRevisionIsDraft == true) {
|
||||||
}
|
|
||||||
else if(data.orgRevisionIsCurrent == false && data.orgRevisionIsDraft == true) {
|
|
||||||
posMasterRoot = await this.posMasterRepository.find({
|
posMasterRoot = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild1Id: IsNull(),
|
orgChild1Id: IsNull(),
|
||||||
next_holderId: Not(IsNull())
|
next_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["next_holder", "orgRoot"]
|
relations: ["next_holder", "orgRoot"],
|
||||||
});
|
});
|
||||||
posMasterChild1 = await this.posMasterRepository.find({
|
posMasterChild1 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild2Id: IsNull(),
|
orgChild2Id: IsNull(),
|
||||||
orgChild1Id: Not(IsNull()),
|
orgChild1Id: Not(IsNull()),
|
||||||
next_holderId: Not(IsNull())
|
next_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["next_holder", "orgChild1"]
|
relations: ["next_holder", "orgChild1"],
|
||||||
});
|
});
|
||||||
posMasterChild2 = await this.posMasterRepository.find({
|
posMasterChild2 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild3Id: IsNull(),
|
orgChild3Id: IsNull(),
|
||||||
orgChild2Id: Not(IsNull()),
|
orgChild2Id: Not(IsNull()),
|
||||||
next_holderId: Not(IsNull())
|
next_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["next_holder", "orgChild2"]
|
relations: ["next_holder", "orgChild2"],
|
||||||
});
|
});
|
||||||
posMasterChild3 = await this.posMasterRepository.find({
|
posMasterChild3 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild4Id: IsNull(),
|
orgChild4Id: IsNull(),
|
||||||
orgChild3Id: Not(IsNull()),
|
orgChild3Id: Not(IsNull()),
|
||||||
next_holderId: Not(IsNull())
|
next_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["next_holder", "orgChild3"]
|
relations: ["next_holder", "orgChild3"],
|
||||||
});
|
});
|
||||||
posMasterChild4 = await this.posMasterRepository.find({
|
posMasterChild4 = await this.posMasterRepository.find({
|
||||||
where: {
|
where: {
|
||||||
orgRevisionId: data.id,
|
orgRevisionId: data.id,
|
||||||
orgChild4Id: Not(IsNull()),
|
orgChild4Id: Not(IsNull()),
|
||||||
next_holderId: Not(IsNull())
|
next_holderId: Not(IsNull()),
|
||||||
},
|
},
|
||||||
relations:["next_holder", "orgChild4"]
|
relations: ["next_holder", "orgChild4"],
|
||||||
});
|
});
|
||||||
|
|
||||||
let formattedData = posMasterRoot
|
let formattedData = posMasterRoot
|
||||||
.filter((x:any) => x.next_holderId !=null)
|
.filter((x: any) => x.next_holderId != null)
|
||||||
.map((x0:PosMaster) => ({
|
.map((x0: PosMaster) => ({
|
||||||
personID: x0.next_holder.id,
|
personID: x0.next_holder.id,
|
||||||
name: x0.next_holder.firstName,
|
name: x0.next_holder.firstName,
|
||||||
avatar: x0.next_holder.avatar,
|
avatar: x0.next_holder.avatar,
|
||||||
positionName: x0.next_holder.position,
|
positionName: x0.next_holder.position,
|
||||||
positionNum: x0.orgRoot.orgRootShortName+x0.posMasterNo,
|
positionNum: x0.orgRoot.orgRootShortName + x0.posMasterNo,
|
||||||
positionNumInt: x0.posMasterNo,
|
positionNumInt: x0.posMasterNo,
|
||||||
departmentName: x0.orgRoot.orgRootName,
|
departmentName: x0.orgRoot.orgRootName,
|
||||||
organizationId: x0.orgRoot.id,
|
organizationId: x0.orgRoot.id,
|
||||||
children: posMasterChild1
|
children: posMasterChild1
|
||||||
.filter((x:any) => x.next_holderId !=null && x.orgRootId == x0.orgRootId)
|
.filter((x: any) => x.next_holderId != null && x.orgRootId == x0.orgRootId)
|
||||||
.map((x1:PosMaster)=>({
|
.map((x1: PosMaster) => ({
|
||||||
personID: x1.next_holder.id,
|
personID: x1.next_holder.id,
|
||||||
name: x1.next_holder.firstName,
|
name: x1.next_holder.firstName,
|
||||||
avatar: x1.next_holder.avatar,
|
avatar: x1.next_holder.avatar,
|
||||||
positionName: x1.next_holder.position,
|
positionName: x1.next_holder.position,
|
||||||
positionNum: x1.orgChild1.orgChild1ShortName+x1.posMasterNo,
|
positionNum: x1.orgChild1.orgChild1ShortName + x1.posMasterNo,
|
||||||
positionNumInt: x1.posMasterNo,
|
positionNumInt: x1.posMasterNo,
|
||||||
departmentName: x1.orgChild1.orgChild1Name,
|
departmentName: x1.orgChild1.orgChild1Name,
|
||||||
organizationId: x1.orgChild1.id,
|
organizationId: x1.orgChild1.id,
|
||||||
children: posMasterChild2
|
children: posMasterChild2
|
||||||
.filter((x:any) => x.next_holderId !=null && x.child1Id == x1.orgChild1Id)
|
.filter((x: any) => x.next_holderId != null && x.child1Id == x1.orgChild1Id)
|
||||||
.map((x2:PosMaster) =>({
|
.map((x2: PosMaster) => ({
|
||||||
personID: x2.next_holder.id,
|
personID: x2.next_holder.id,
|
||||||
name: x2.next_holder.firstName,
|
name: x2.next_holder.firstName,
|
||||||
avatar: x2.next_holder.avatar,
|
avatar: x2.next_holder.avatar,
|
||||||
positionName: x2.next_holder.position,
|
positionName: x2.next_holder.position,
|
||||||
positionNum: x2.orgChild2.orgChild2ShortName+x2.posMasterNo,
|
positionNum: x2.orgChild2.orgChild2ShortName + x2.posMasterNo,
|
||||||
positionNumInt: x2.posMasterNo,
|
positionNumInt: x2.posMasterNo,
|
||||||
departmentName: x2.orgChild2.orgChild2Name,
|
departmentName: x2.orgChild2.orgChild2Name,
|
||||||
organizationId: x2.orgChild2.id,
|
organizationId: x2.orgChild2.id,
|
||||||
children: posMasterChild3
|
children: posMasterChild3
|
||||||
.filter((x:any) => x.next_holderId !=null && x.child2Id == x2.orgChild2Id)
|
.filter((x: any) => x.next_holderId != null && x.child2Id == x2.orgChild2Id)
|
||||||
.map((x3:PosMaster) =>({
|
.map((x3: PosMaster) => ({
|
||||||
personID: x3.next_holder.id,
|
personID: x3.next_holder.id,
|
||||||
name: x3.next_holder.firstName,
|
name: x3.next_holder.firstName,
|
||||||
avatar: x3.next_holder.avatar,
|
avatar: x3.next_holder.avatar,
|
||||||
positionName: x3.next_holder.position,
|
positionName: x3.next_holder.position,
|
||||||
positionNum: x3.orgChild3.orgChild3ShortName+x3.posMasterNo,
|
positionNum: x3.orgChild3.orgChild3ShortName + x3.posMasterNo,
|
||||||
positionNumInt: x3.posMasterNo,
|
positionNumInt: x3.posMasterNo,
|
||||||
departmentName: x3.orgChild3.orgChild3Name,
|
departmentName: x3.orgChild3.orgChild3Name,
|
||||||
organizationId: x3.orgChild3.id,
|
organizationId: x3.orgChild3.id,
|
||||||
children: posMasterChild4
|
children: posMasterChild4
|
||||||
.filter((x:any) => x.next_holderId !=null && x.child3Id == x3.orgChild3Id)
|
.filter((x: any) => x.next_holderId != null && x.child3Id == x3.orgChild3Id)
|
||||||
.map((x4:PosMaster) =>({
|
.map((x4: PosMaster) => ({
|
||||||
personID: x4.next_holder.id,
|
personID: x4.next_holder.id,
|
||||||
name: x4.next_holder.firstName,
|
name: x4.next_holder.firstName,
|
||||||
avatar: x4.next_holder.avatar,
|
avatar: x4.next_holder.avatar,
|
||||||
positionName: x4.next_holder.position,
|
positionName: x4.next_holder.position,
|
||||||
positionNum: x4.orgChild4.orgChild4ShortName+x4.posMasterNo,
|
positionNum: x4.orgChild4.orgChild4ShortName + x4.posMasterNo,
|
||||||
positionNumInt: x4.posMasterNo,
|
positionNumInt: x4.posMasterNo,
|
||||||
departmentName: x4.orgChild4.orgChild4Name,
|
departmentName: x4.orgChild4.orgChild4Name,
|
||||||
organizationId: x4.orgChild4.id,
|
organizationId: x4.orgChild4.id,
|
||||||
}))
|
})),
|
||||||
}))
|
})),
|
||||||
}))
|
})),
|
||||||
}))
|
})),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const formattedData_ = {
|
const formattedData_ = {
|
||||||
personID: "",
|
personID: "",
|
||||||
name: "",
|
name: "",
|
||||||
|
|
@ -2006,11 +2005,10 @@ export class OrganizationController extends Controller {
|
||||||
positionNumInt: null,
|
positionNumInt: null,
|
||||||
departmentName: data.orgRevisionName,
|
departmentName: data.orgRevisionName,
|
||||||
organizationId: data.id,
|
organizationId: data.id,
|
||||||
children: formattedData
|
children: formattedData,
|
||||||
};
|
};
|
||||||
return new HttpSuccess([formattedData_]);
|
return new HttpSuccess([formattedData_]);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return new HttpSuccess([
|
return new HttpSuccess([
|
||||||
{
|
{
|
||||||
personID: "",
|
personID: "",
|
||||||
|
|
@ -2021,8 +2019,8 @@ export class OrganizationController extends Controller {
|
||||||
positionNumInt: null,
|
positionNumInt: null,
|
||||||
departmentName: data.orgRevisionName,
|
departmentName: data.orgRevisionName,
|
||||||
organizationId: data.id,
|
organizationId: data.id,
|
||||||
children: []
|
children: [],
|
||||||
}
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3718,15 +3716,15 @@ export class OrganizationController extends Controller {
|
||||||
});
|
});
|
||||||
if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
|
if (!root) throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root");
|
||||||
const posMaster = await this.posMasterRepository.find({
|
const posMaster = await this.posMasterRepository.find({
|
||||||
where: { orgRootId: root.id, orgChild1Id: IsNull() },
|
where: { orgRootId: root.id, orgChild1Id: IsNull(), current_holder: Not(IsNull()) },
|
||||||
relations: ["current_holder"],
|
relations: ["current_holder"],
|
||||||
});
|
});
|
||||||
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
if (!posMaster) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่ง");
|
||||||
|
|
||||||
const maps = posMaster.map((posMaster) => ({
|
const maps = posMaster.map((posMaster) => ({
|
||||||
id: posMaster.current_holder.id,
|
id: posMaster?.current_holder?.id,
|
||||||
name: `${posMaster.current_holder.prefix}${posMaster.current_holder.firstName} ${posMaster.current_holder.lastName}`,
|
name: `${posMaster?.current_holder?.prefix}${posMaster?.current_holder?.firstName} ${posMaster?.current_holder?.lastName}`,
|
||||||
positionName: posMaster.current_holder.position,
|
positionName: posMaster?.current_holder?.position,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return new HttpSuccess(maps);
|
return new HttpSuccess(maps);
|
||||||
|
|
|
||||||
58
src/interfaces/permission.ts
Normal file
58
src/interfaces/permission.ts
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Request,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Patch,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Path,
|
||||||
|
} from "tsoa";
|
||||||
|
import axios from "axios";
|
||||||
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
|
import CallAPI from "./call-api";
|
||||||
|
import HttpError from "./http-error";
|
||||||
|
import HttpStatus from "./http-status";
|
||||||
|
|
||||||
|
class CheckAuth {
|
||||||
|
public async Permission(req: RequestWithUser, system: string, action: string) {
|
||||||
|
await new CallAPI()
|
||||||
|
.GetData(req, "/org/permission")
|
||||||
|
.then((x) => {
|
||||||
|
let permission = false;
|
||||||
|
let role = x.roles.find((x: any) => x.authSysId == system);
|
||||||
|
if (!role) throw "ไม่มีสิทธิ์เข้าระบบ";
|
||||||
|
if (action.trim().toLocaleUpperCase() == "CREATE") permission = role.attrIsCreate;
|
||||||
|
if (action.trim().toLocaleUpperCase() == "DELETE") permission = role.attrIsDelete;
|
||||||
|
if (action.trim().toLocaleUpperCase() == "GET") permission = role.attrIsGet;
|
||||||
|
if (action.trim().toLocaleUpperCase() == "LIST") permission = role.attrIsList;
|
||||||
|
if (action.trim().toLocaleUpperCase() == "UPDATE") permission = role.attrIsUpdate;
|
||||||
|
if (role.attrOwnership == "OWNER") permission = true;
|
||||||
|
if (permission == false) throw "ไม่มีสิทธิ์ใช้งานระบบนี้";
|
||||||
|
return role.attrPrivilege;
|
||||||
|
})
|
||||||
|
.catch((x) => {
|
||||||
|
throw new HttpError(HttpStatus.FORBIDDEN, x);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public async PermissionCreate(req: RequestWithUser, system: string) {
|
||||||
|
this.Permission(req, system, "CREATE");
|
||||||
|
}
|
||||||
|
public async PermissionDelete(req: RequestWithUser, system: string) {
|
||||||
|
this.Permission(req, system, "DELETE");
|
||||||
|
}
|
||||||
|
public async PermissionGet(req: RequestWithUser, system: string) {
|
||||||
|
this.Permission(req, system, "GET");
|
||||||
|
}
|
||||||
|
public async PermissionList(req: RequestWithUser, system: string) {
|
||||||
|
this.Permission(req, system, "LIST");
|
||||||
|
}
|
||||||
|
public async PermissionUpdate(req: RequestWithUser, system: string) {
|
||||||
|
this.Permission(req, system, "UPDATE");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CheckAuth;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue