api find org only
This commit is contained in:
parent
c0e2c10cee
commit
97251fdd6e
1 changed files with 131 additions and 25 deletions
|
|
@ -85,6 +85,7 @@ import { OrgChild4 } from "../entities/OrgChild4";
|
||||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||||
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
import { ProfileAssistance } from "../entities/ProfileAssistance";
|
||||||
import { CommandRecive } from "../entities/CommandRecive";
|
import { CommandRecive } from "../entities/CommandRecive";
|
||||||
|
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||||
@Route("api/v1/org/profile")
|
@Route("api/v1/org/profile")
|
||||||
@Tags("Profile")
|
@Tags("Profile")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -101,6 +102,7 @@ export class ProfileController extends Controller {
|
||||||
private orgChild3Repo = AppDataSource.getRepository(OrgChild3);
|
private orgChild3Repo = AppDataSource.getRepository(OrgChild3);
|
||||||
private orgChild4Repo = AppDataSource.getRepository(OrgChild4);
|
private orgChild4Repo = AppDataSource.getRepository(OrgChild4);
|
||||||
private posMasterRepo = AppDataSource.getRepository(PosMaster);
|
private posMasterRepo = AppDataSource.getRepository(PosMaster);
|
||||||
|
private employeePosMasterRepo = AppDataSource.getRepository(EmployeePosMaster);
|
||||||
private profileRepo = AppDataSource.getRepository(Profile);
|
private profileRepo = AppDataSource.getRepository(Profile);
|
||||||
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
|
||||||
private profileHistoryRepo = AppDataSource.getRepository(ProfileHistory);
|
private profileHistoryRepo = AppDataSource.getRepository(ProfileHistory);
|
||||||
|
|
@ -2053,6 +2055,109 @@ export class ProfileController extends Controller {
|
||||||
return new HttpSuccess({ caregiver, commander, chairman });
|
return new HttpSuccess({ caregiver, commander, chairman });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ข้อมูลทะเบียนประวัติตาม profileId
|
||||||
|
*
|
||||||
|
* @summary ข้อมูลองค์กรของ Profile (ADMIN)
|
||||||
|
*
|
||||||
|
* @param {string} profileId Profile ID
|
||||||
|
*/
|
||||||
|
@Get("org-user/{profileId}")
|
||||||
|
async getOrgUserByProfileId(@Path() profileId: string) {
|
||||||
|
// 1. หาข้อมูล org hierarchy สำหรับ profile นี้
|
||||||
|
const posMaster = await this.posMasterRepo.findOne({
|
||||||
|
where: {
|
||||||
|
current_holderId: profileId,
|
||||||
|
orgRevision: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
orgRoot: {
|
||||||
|
id: true,
|
||||||
|
orgRootName: true,
|
||||||
|
},
|
||||||
|
orgChild1: {
|
||||||
|
id: true,
|
||||||
|
orgChild1Name: true,
|
||||||
|
},
|
||||||
|
orgChild2: {
|
||||||
|
id: true,
|
||||||
|
orgChild2Name: true,
|
||||||
|
},
|
||||||
|
orgChild3: {
|
||||||
|
id: true,
|
||||||
|
orgChild3Name: true,
|
||||||
|
},
|
||||||
|
orgChild4: {
|
||||||
|
id: true,
|
||||||
|
orgChild4Name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||||
|
});
|
||||||
|
|
||||||
|
// 2. ถ้าไม่พบใน PosMaster ให้ลองหาใน EmployeePosMaster
|
||||||
|
if (!posMaster) {
|
||||||
|
const employeePosMaster = await this.employeePosMasterRepo.findOne({
|
||||||
|
where: {
|
||||||
|
current_holderId: profileId,
|
||||||
|
orgRevision: {
|
||||||
|
orgRevisionIsCurrent: true,
|
||||||
|
orgRevisionIsDraft: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
orgRoot: {
|
||||||
|
id: true,
|
||||||
|
orgRootName: true,
|
||||||
|
},
|
||||||
|
orgChild1: {
|
||||||
|
id: true,
|
||||||
|
orgChild1Name: true,
|
||||||
|
},
|
||||||
|
orgChild2: {
|
||||||
|
id: true,
|
||||||
|
orgChild2Name: true,
|
||||||
|
},
|
||||||
|
orgChild3: {
|
||||||
|
id: true,
|
||||||
|
orgChild3Name: true,
|
||||||
|
},
|
||||||
|
orgChild4: {
|
||||||
|
id: true,
|
||||||
|
orgChild4Name: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!employeePosMaster) {
|
||||||
|
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งสำหรับ Profile นี้");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
root: employeePosMaster.orgRoot?.orgRootName ?? null,
|
||||||
|
child1: employeePosMaster.orgChild1?.orgChild1Name ?? null,
|
||||||
|
child2: employeePosMaster.orgChild2?.orgChild2Name ?? null,
|
||||||
|
child3: employeePosMaster.orgChild3?.orgChild3Name ?? null,
|
||||||
|
child4: employeePosMaster.orgChild4?.orgChild4Name ?? null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Return ข้อมูล org hierarchy
|
||||||
|
return new HttpSuccess({
|
||||||
|
root: posMaster.orgRoot?.orgRootName ?? null,
|
||||||
|
child1: posMaster.orgChild1?.orgChild1Name ?? null,
|
||||||
|
child2: posMaster.orgChild2?.orgChild2Name ?? null,
|
||||||
|
child3: posMaster.orgChild3?.orgChild3Name ?? null,
|
||||||
|
child4: posMaster.orgChild4?.orgChild4Name ?? null,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API
|
* API
|
||||||
*
|
*
|
||||||
|
|
@ -6257,21 +6362,20 @@ export class ProfileController extends Controller {
|
||||||
]
|
]
|
||||||
.filter(Boolean)
|
.filter(Boolean)
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
const shortName =
|
const shortName = !holder
|
||||||
!holder
|
? null
|
||||||
? null
|
: holder.orgChild4 != null
|
||||||
: holder.orgChild4 != null
|
? `${holder.orgChild4.orgChild4ShortName} ${holder.posMasterNo}`
|
||||||
? `${holder.orgChild4.orgChild4ShortName} ${holder.posMasterNo}`
|
: holder.orgChild3 != null
|
||||||
: holder.orgChild3 != null
|
? `${holder.orgChild3.orgChild3ShortName} ${holder.posMasterNo}`
|
||||||
? `${holder.orgChild3.orgChild3ShortName} ${holder.posMasterNo}`
|
: holder.orgChild2 != null
|
||||||
: holder.orgChild2 != null
|
? `${holder.orgChild2.orgChild2ShortName} ${holder.posMasterNo}`
|
||||||
? `${holder.orgChild2.orgChild2ShortName} ${holder.posMasterNo}`
|
: holder.orgChild1 != null
|
||||||
: holder.orgChild1 != null
|
? `${holder.orgChild1.orgChild1ShortName} ${holder.posMasterNo}`
|
||||||
? `${holder.orgChild1.orgChild1ShortName} ${holder.posMasterNo}`
|
: holder.orgRoot != null
|
||||||
: holder.orgRoot != null
|
? `${holder.orgRoot.orgRootShortName} ${holder.posMasterNo}`
|
||||||
? `${holder.orgRoot.orgRootShortName} ${holder.posMasterNo}`
|
: null;
|
||||||
: null;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: _data.id,
|
id: _data.id,
|
||||||
|
|
@ -8271,15 +8375,16 @@ export class ProfileController extends Controller {
|
||||||
body: {
|
body: {
|
||||||
fieldName?: string | null;
|
fieldName?: string | null;
|
||||||
keyword?: string;
|
keyword?: string;
|
||||||
system?: string;
|
system?: string;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
// ค้นหารายชื่อถ้าไม่ส่ง system มาให้ default ตามทะเบียนประวัติ
|
||||||
let _system:string ="SYS_REGISTRY_OFFICER";
|
let _system: string = "SYS_REGISTRY_OFFICER";
|
||||||
if(body.system)
|
if (body.system) _system = body.system;
|
||||||
_system = body.system;
|
|
||||||
let _data = await new permission().PermissionOrgList(request, _system);
|
let _data = await new permission().PermissionOrgList(request, _system);
|
||||||
const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true } });
|
const findRevision = await this.orgRevisionRepo.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
if (!findRevision) {
|
if (!findRevision) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
|
||||||
}
|
}
|
||||||
|
|
@ -8299,14 +8404,15 @@ export class ProfileController extends Controller {
|
||||||
// IFNULL(orgRoot.orgRootShortName, '')," ",
|
// IFNULL(orgRoot.orgRootShortName, '')," ",
|
||||||
// IFNULL(current_holders.posMasterNo , '')
|
// IFNULL(current_holders.posMasterNo , '')
|
||||||
// ) LIKE :keyword`;
|
// ) LIKE :keyword`;
|
||||||
let queryLike = "1=1"
|
let queryLike = "1=1";
|
||||||
switch (body.fieldName) {
|
switch (body.fieldName) {
|
||||||
case "citizenId":
|
case "citizenId":
|
||||||
queryLike = "profile.citizenId LIKE :keyword";
|
queryLike = "profile.citizenId LIKE :keyword";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "fullName":
|
case "fullName":
|
||||||
queryLike = "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
queryLike =
|
||||||
|
"CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "position":
|
case "position":
|
||||||
|
|
@ -8314,7 +8420,7 @@ export class ProfileController extends Controller {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "posNo":
|
case "posNo":
|
||||||
queryLike = `
|
queryLike = `
|
||||||
CASE
|
CASE
|
||||||
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, " ", current_holders.posMasterNo)
|
WHEN current_holders.orgChild4Id IS NOT NULL THEN CONCAT(orgChild4.orgChild4ShortName, " ", current_holders.posMasterNo)
|
||||||
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", current_holders.posMasterNo)
|
WHEN current_holders.orgChild3Id IS NOT NULL THEN CONCAT(orgChild3.orgChild3ShortName, " ", current_holders.posMasterNo)
|
||||||
|
|
@ -8338,10 +8444,10 @@ export class ProfileController extends Controller {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
queryLike = "1=1"
|
queryLike = "1=1";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [findProfile, total] = await this.profileRepo
|
const [findProfile, total] = await this.profileRepo
|
||||||
.createQueryBuilder("profile")
|
.createQueryBuilder("profile")
|
||||||
.leftJoinAndSelect("profile.posType", "posType")
|
.leftJoinAndSelect("profile.posType", "posType")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue