api ตำแหน่งทั้งหมด

This commit is contained in:
Bright 2024-02-02 16:15:51 +07:00
parent 7388202061
commit 971c611c5d

View file

@ -939,7 +939,7 @@ export class PositionController extends Controller {
item.orgRoot == null
? "-"
: item.orgChild1 == null
? item.orgRoot
? item.orgRoot.orgRootShortName
: item.orgChild2 == null
? item.orgChild1.orgChild1ShortName
: item.orgChild3 == null
@ -1044,4 +1044,212 @@ export class PositionController extends Controller {
return error;
}
}
/**
* API
*
* @summary ORG_055 - (ADMIN) #60
*
*/
@Post("summary")
async PositionSummary(
@Body() requestBody: { id: string; type: number },
) {
try {
let summary: any;
let totalPosition: any;
let totalPositionCurrentUse: any;
let totalPositionCurrentVacant: any;
let totalPositionNextUse: any;
let totalPositionNextVacant: any;
switch(requestBody.type){
case 0: {
const NodeId = await this.posMasterRepository.findOne({where: {orgRootId: requestBody.id}});
if(!NodeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id);
}
totalPosition = await this.posMasterRepository.count({
where: { orgRootId: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
profileIdNextHolder: IsNull() && "",
},
});
break;
}
case 1: {
const NodeId = await this.posMasterRepository.findOne({where: {orgChild1Id: requestBody.id}});
if(!NodeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild1Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
},
});
break;
}
case 2: {
const NodeId = await this.posMasterRepository.findOne({where: {orgChild2Id: requestBody.id}});
if(!NodeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild2Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
},
});
break;
}
case 3: {
const NodeId = await this.posMasterRepository.findOne({where: {orgChild3Id: requestBody.id}});
if(!NodeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild3Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
},
});
break;
}
case 4: {
const NodeId = await this.posMasterRepository.findOne({where: {orgChild4Id: requestBody.id}});
if(!NodeId){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild4Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdCurrentHolder: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
profileIdNextHolder: IsNull() && "",
},
});
break;
}
default:
break;
}
summary = {
totalPosition: totalPosition,
totalPositionCurrentUse: totalPositionCurrentUse,
totalPositionCurrentVacant: totalPositionCurrentVacant,
totalPositionNextUse: totalPositionNextUse,
totalPositionNextVacant: totalPositionNextVacant
}
return new HttpSuccess(summary);
} catch (error) {
return error;
}
}
}