Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
* 'develop' of github.com:Frappet/bma-ehr-organization: fix sort # Conflicts: # src/controllers/ProfileController.ts
This commit is contained in:
commit
682ff3a061
1 changed files with 33 additions and 10 deletions
|
|
@ -6114,8 +6114,10 @@ export class ProfileController extends Controller {
|
||||||
@Query() nodeId?: string,
|
@Query() nodeId?: string,
|
||||||
@Query() isAll?: boolean,
|
@Query() isAll?: boolean,
|
||||||
@Query() retireType?: string,
|
@Query() retireType?: string,
|
||||||
@Query() sortBy?: string,
|
// @Query() sortBy: string = "current_holders.posMasterNo",
|
||||||
@Query() sort: "ASC" | "DESC" = "ASC",
|
@Query() sort: "ASC" | "DESC" = "ASC",
|
||||||
|
@Query("sortBy") sortBy?: string,
|
||||||
|
@Query("descending") descending?: boolean,
|
||||||
) {
|
) {
|
||||||
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
let _data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
|
||||||
let queryLike =
|
let queryLike =
|
||||||
|
|
@ -6155,7 +6157,7 @@ export class ProfileController extends Controller {
|
||||||
nodeCondition = nodeCondition + nodeAll;
|
nodeCondition = nodeCondition + nodeAll;
|
||||||
|
|
||||||
// เลือกเฉพาะฟิลด์ที่จำเป็น
|
// เลือกเฉพาะฟิลด์ที่จำเป็น
|
||||||
const [record, total] = await this.profileRepo
|
let query = await this.profileRepo
|
||||||
.createQueryBuilder("profile")
|
.createQueryBuilder("profile")
|
||||||
.leftJoin("profile.posLevel", "posLevel")
|
.leftJoin("profile.posLevel", "posLevel")
|
||||||
.leftJoin("profile.posType", "posType")
|
.leftJoin("profile.posType", "posType")
|
||||||
|
|
@ -6201,6 +6203,9 @@ export class ProfileController extends Controller {
|
||||||
"orgChild4.orgChild4Name",
|
"orgChild4.orgChild4Name",
|
||||||
"orgChild4.orgChild4ShortName",
|
"orgChild4.orgChild4ShortName",
|
||||||
"orgChild4.orgChild4Order",
|
"orgChild4.orgChild4Order",
|
||||||
|
"positions.id",
|
||||||
|
"posExecutive.id",
|
||||||
|
"posExecutive.posExecutiveName",
|
||||||
])
|
])
|
||||||
// .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
// .where(node && nodeId ? "current_holders.orgRevisionId = :orgRevisionId" : "1=1", {
|
||||||
// orgRevisionId:
|
// orgRevisionId:
|
||||||
|
|
@ -6277,14 +6282,30 @@ export class ProfileController extends Controller {
|
||||||
qb.orWhere(searchKeyword ? queryLike : "1=1", { keyword: `%${searchKeyword}%` });
|
qb.orWhere(searchKeyword ? queryLike : "1=1", { keyword: `%${searchKeyword}%` });
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order")
|
.addSelect("CASE WHEN current_holders.posMasterNo IS NULL THEN 1 ELSE 0 END", "sort_order");
|
||||||
.orderBy(`${sortBy ? sortBy : "sort_order"}`, `${sort}`)
|
|
||||||
|
if (sortBy) {
|
||||||
|
if (sortBy === "posLevel") {
|
||||||
|
query = query.orderBy(`posLevel.posLevelName`, descending ? "DESC" : "ASC");
|
||||||
|
} else if (sortBy === "posType") {
|
||||||
|
query = query.orderBy(`posType.posTypeName`, descending ? "DESC" : "ASC");
|
||||||
|
} else if (sortBy === "posExecutive") {
|
||||||
|
query = query.orderBy(`posExecutive.posExecutiveName`, descending ? "DESC" : "ASC");
|
||||||
|
} else {
|
||||||
|
query = query.orderBy(`profile.${sortBy}`, descending ? "DESC" : "ASC");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
query = query
|
||||||
|
.orderBy("sort_order", "ASC")
|
||||||
.addOrderBy("orgRoot.orgRootOrder", sort)
|
.addOrderBy("orgRoot.orgRootOrder", sort)
|
||||||
.addOrderBy("orgChild1.orgChild1Order", sort)
|
.addOrderBy("orgChild1.orgChild1Order", sort)
|
||||||
.addOrderBy("orgChild2.orgChild2Order", sort)
|
.addOrderBy("orgChild2.orgChild2Order", sort)
|
||||||
.addOrderBy("orgChild3.orgChild3Order", sort)
|
.addOrderBy("orgChild3.orgChild3Order", sort)
|
||||||
.addOrderBy("orgChild4.orgChild4Order", sort)
|
.addOrderBy("orgChild4.orgChild4Order", sort)
|
||||||
.addOrderBy("current_holders.posMasterNo", sort)
|
.addOrderBy("current_holders.posMasterNo", sort);
|
||||||
|
}
|
||||||
|
|
||||||
|
const [record, total] = await query
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
.take(pageSize)
|
.take(pageSize)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
@ -6331,6 +6352,8 @@ export class ProfileController extends Controller {
|
||||||
posLevelId: _data.posLevel?.id ?? null,
|
posLevelId: _data.posLevel?.id ?? null,
|
||||||
posTypeId: _data.posType?.id ?? null,
|
posTypeId: _data.posType?.id ?? null,
|
||||||
position: _data.position,
|
position: _data.position,
|
||||||
|
posExecutive:
|
||||||
|
_data.current_holders[0]?.positions[0]?.posExecutive?.posExecutiveName ?? null,
|
||||||
posNo: shortName ?? null,
|
posNo: shortName ?? null,
|
||||||
rootId: holder?.orgRoot?.id ?? null,
|
rootId: holder?.orgRoot?.id ?? null,
|
||||||
root: holder?.orgRoot?.orgRootName ?? null,
|
root: holder?.orgRoot?.orgRootName ?? null,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue