This commit is contained in:
parent
5e5c194e33
commit
6312b940a3
1 changed files with 88 additions and 1 deletions
|
|
@ -36,6 +36,8 @@ import { calculateRetireLaw } from "../interfaces/utils";
|
|||
import Extension from "../interfaces/extension";
|
||||
import { PosMasterHistory } from "../entities/PosMasterHistory";
|
||||
import { PosMasterEmployeeHistory } from "../entities/PosMasterEmployeeHistory";
|
||||
import { PosMasterAssign } from "../entities/PosMasterAssign";
|
||||
import { Assign } from "../entities/Assign";
|
||||
@Route("api/v1/org/dotnet")
|
||||
@Tags("Dotnet")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -61,7 +63,8 @@ export class OrganizationDotnetController extends Controller {
|
|||
private empPosMasterRepository = AppDataSource.getRepository(EmployeePosMaster);
|
||||
private insigniaRepo = AppDataSource.getRepository(ProfileInsignia);
|
||||
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||
|
||||
private posMasterAssignRepo = AppDataSource.getRepository(PosMasterAssign);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
/**
|
||||
* ทำไว้ให้ service อื่นๆ ภายในระบบ call มาตรวจสอบเลขบัตรประจำตัวประชาชน
|
||||
*
|
||||
|
|
@ -7043,4 +7046,88 @@ export class OrganizationDotnetController extends Controller {
|
|||
|
||||
return new HttpSuccess(profile_);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหา กจ.
|
||||
*
|
||||
* @summary API ค้นหา กจ.
|
||||
*
|
||||
*/
|
||||
@Post("find-staff")
|
||||
async findHigher(
|
||||
@Body()
|
||||
requestBody: {
|
||||
profileId: string;
|
||||
assignId: string;
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const profile = await this.profileRepo.findOne({
|
||||
where: { id: requestBody.profileId },
|
||||
relations: [
|
||||
"current_holders",
|
||||
"current_holders.orgRevision"
|
||||
],
|
||||
});
|
||||
|
||||
if (!profile)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
where: { id: requestBody.assignId.trim().toLocaleUpperCase() },
|
||||
});
|
||||
|
||||
if (!assign)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลระบบสิทธิ์หน้าที่ความรับผิดชอบ");
|
||||
|
||||
const currentHolder = profile.current_holders?.find(
|
||||
h => h.orgRevision?.orgRevisionIsCurrent && !h.orgRevision?.orgRevisionIsDraft,
|
||||
);
|
||||
|
||||
if (!currentHolder)
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "โปรไฟล์นี้ไม่ได้ครองตำแหน่งในปัจจุบัน");
|
||||
|
||||
const posMasters = await this.posMasterRepository
|
||||
.createQueryBuilder("pm")
|
||||
.select([
|
||||
"pm.current_holderId AS profileId",
|
||||
"profile.keycloak AS keycloak",
|
||||
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) AS fullName",
|
||||
"pm.orgRootId AS rootId",
|
||||
"pm.orgChild1Id AS orgChild1Id",
|
||||
"pm.orgChild2Id AS orgChild2Id",
|
||||
"pm.orgChild3Id AS orgChild3Id",
|
||||
"pm.orgChild4Id AS orgChild4Id",
|
||||
"orgRoot.ancestorDNA AS rootDnaId",
|
||||
"orgChild1.ancestorDNA AS child1DnaId",
|
||||
"orgChild2.ancestorDNA AS child2DnaId",
|
||||
"orgChild3.ancestorDNA AS child3DnaId",
|
||||
"orgChild4.ancestorDNA AS child4DnaId",
|
||||
])
|
||||
.distinct(true)
|
||||
// ต้องมี posMasterAssign
|
||||
.innerJoin("posMasterAssign", "assign", "assign.posMasterId = pm.id")
|
||||
// join เพื่อเอา ancestorDNA
|
||||
.leftJoin("pm.orgRoot", "orgRoot")
|
||||
.leftJoin("pm.orgChild1", "orgChild1")
|
||||
.leftJoin("pm.orgChild2", "orgChild2")
|
||||
.leftJoin("pm.orgChild3", "orgChild3")
|
||||
.leftJoin("pm.orgChild4", "orgChild4")
|
||||
.leftJoin("pm.current_holder", "profile")
|
||||
.where("pm.orgRevisionId = :orgRevisionId", {
|
||||
orgRevisionId: currentHolder.orgRevisionId,
|
||||
})
|
||||
.andWhere("pm.orgRootId = :orgRootId", {
|
||||
orgRootId: currentHolder.orgRootId,
|
||||
})
|
||||
.andWhere("pm.current_holderId != :profileId", {
|
||||
profileId: profile.id,
|
||||
})
|
||||
.andWhere("assign.assignId = :assignId", {
|
||||
assignId: assign.id
|
||||
})
|
||||
.getRawMany();
|
||||
|
||||
return new HttpSuccess(posMasters);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue