no message
This commit is contained in:
parent
5cb6126b39
commit
16324a09fd
2 changed files with 121 additions and 16 deletions
|
|
@ -2831,4 +2831,36 @@ export class OrganizationController extends Controller {
|
|||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API หาสำนักทั้งหมด
|
||||
*
|
||||
* @summary หาสำนักทั้งหมด
|
||||
*
|
||||
*/
|
||||
@Get("active/root")
|
||||
async GetActiveRoot() {
|
||||
try {
|
||||
const orgRevisionActive = await this.orgRevisionRepository.findOne({
|
||||
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
|
||||
});
|
||||
if (!orgRevisionActive) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร๋อยู่ตอนนี้");
|
||||
}
|
||||
|
||||
const data = await this.orgRootRepository.find({
|
||||
where: { orgRevisionId: orgRevisionActive.id },
|
||||
relations: [
|
||||
"orgRevision",
|
||||
"orgChild1s",
|
||||
"orgChild1s.orgChild2s",
|
||||
"orgChild1s.orgChild2s.orgChild3s",
|
||||
"orgChild1s.orgChild2s.orgChild3s.orgChild4s",
|
||||
],
|
||||
});
|
||||
return new HttpSuccess(data);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -255,10 +255,10 @@ export class ProfileController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get()
|
||||
async listProfile(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
async listProfile(
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [profile, total] = await this.profileRepository.findAndCount({
|
||||
select: [
|
||||
|
|
@ -279,15 +279,9 @@ export class ProfileController extends Controller {
|
|||
const formattedKeyword = keyword.toLowerCase().replace(/\s+/g, "");
|
||||
const filteredProfile = profile.filter(
|
||||
(x) =>
|
||||
(
|
||||
x.prefix +
|
||||
x.firstName +
|
||||
x.lastName
|
||||
)
|
||||
.replace(/\s+/g, "")
|
||||
.includes(formattedKeyword) ||
|
||||
(x.prefix + x.firstName + x.lastName).replace(/\s+/g, "").includes(formattedKeyword) ||
|
||||
x.citizenId?.toString().includes(keyword) ||
|
||||
x.position?.toString().includes(keyword)
|
||||
x.position?.toString().includes(keyword),
|
||||
);
|
||||
|
||||
const formattedData = filteredProfile.map((item) => ({
|
||||
|
|
@ -298,7 +292,7 @@ export class ProfileController extends Controller {
|
|||
citizenId: item.citizenId,
|
||||
position: item.position,
|
||||
posLevelId: item.posLevelId,
|
||||
posTypeId: item.posTypeId
|
||||
posTypeId: item.posTypeId,
|
||||
}));
|
||||
|
||||
return new HttpSuccess({ data: formattedData, total: formattedData.length });
|
||||
|
|
@ -316,10 +310,9 @@ export class ProfileController extends Controller {
|
|||
citizenId: item.citizenId,
|
||||
position: item.position,
|
||||
posLevelId: item.posLevelId,
|
||||
posTypeId: item.posTypeId
|
||||
posTypeId: item.posTypeId,
|
||||
}));
|
||||
return new HttpSuccess({ data: formattedData, total });
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -454,11 +447,21 @@ export class ProfileController extends Controller {
|
|||
async getProfileByKeycloak(@Request() request: { user: Record<string, any> }) {
|
||||
const profile = await this.profileRepository.findOne({
|
||||
where: { keycloak: request.user.sub },
|
||||
relations: ["posLevel", "posType"],
|
||||
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],
|
||||
});
|
||||
if (!profile) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
|
||||
}
|
||||
|
||||
const orgRevisionPublish = await this.orgRevisionRepository
|
||||
.createQueryBuilder("orgRevision")
|
||||
.where("orgRevision.orgRevisionIsDraft = false")
|
||||
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||
.getOne();
|
||||
if (!orgRevisionPublish) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบแบบร่างโครงสร้าง");
|
||||
}
|
||||
|
||||
const _profile = {
|
||||
profileId: profile.id,
|
||||
prefix: profile.prefix,
|
||||
|
|
@ -472,6 +475,76 @@ export class ProfileController extends Controller {
|
|||
posTypeName: profile.posType == null ? null : profile.posType.posTypeName,
|
||||
posTypeRank: profile.posType == null ? null : profile.posType.posTypeRank,
|
||||
posTypeId: profile.posType == null ? null : profile.posType.id,
|
||||
rootId:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
|
||||
?.orgRootId,
|
||||
root:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgRoot
|
||||
.orgRootName,
|
||||
child1Id:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
|
||||
?.orgChild1Id,
|
||||
child1:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild1
|
||||
.orgChild1Name,
|
||||
child2Id:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
|
||||
?.orgChild2Id,
|
||||
child2:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild2
|
||||
.orgChild2Name,
|
||||
child3Id:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
|
||||
?.orgChild3Id,
|
||||
child3:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild3
|
||||
.orgChild3Name,
|
||||
child4Id:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)
|
||||
?.orgChild4Id,
|
||||
child4:
|
||||
profile.current_holders == null ||
|
||||
profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4 ==
|
||||
null
|
||||
? null
|
||||
: profile.current_holders.find((x) => x.orgRevisionId == orgRevisionPublish.id)?.orgChild4
|
||||
.orgChild4Name,
|
||||
};
|
||||
try {
|
||||
return new HttpSuccess(_profile);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue