edit search

This commit is contained in:
mamoss 2025-06-12 15:56:42 +07:00
parent 4ca001e2ff
commit 176924a268
4 changed files with 270 additions and 66 deletions

View file

@ -26,6 +26,7 @@ import { ProfileDevelopment } from "../entities/ProfileDevelopment";
import { ProfileDevelopmentHistory } from "../entities/ProfileDevelopmentHistory";
import { setLogDataDiff } from "../interfaces/utils";
import CallAPI from "../interfaces/call-api";
import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org/profile/development-request")
@Tags("DevelopmentRequest")
@Security("bearerAuth")
@ -35,6 +36,7 @@ export class DevelopmentRequestController extends Controller {
private developmentRequestRepository = AppDataSource.getRepository(DevelopmentRequest);
private developmentProjectRepository = AppDataSource.getRepository(DevelopmentProject);
private developmentHistoryRepository = AppDataSource.getRepository(ProfileDevelopmentHistory);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
@Get("user")
public async getDevelopmentRequestUser(
@ -109,15 +111,23 @@ export class DevelopmentRequestController extends Controller {
@Get("admin")
public async getDevelopmentRequestAdmin(
@Request() req: RequestWithUser,
@Request() request: RequestWithUser,
@Query("status") status: string,
@Query("keyword") keyword: string = "",
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
) {
// await new permission().PermissionList(req, "SYS_REGISTRY_OFFICER");
let data = await new permission().PermissionOrgList(request, "SYS_REGISTRY_OFFICER");
const orgRevisionPublish = await this.orgRevisionRepository
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const [lists, total] = await AppDataSource.getRepository(DevelopmentRequest)
.createQueryBuilder("developmentRequest")
.leftJoinAndSelect("developmentRequest.profile", "profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRevision", "orgRevision")
.andWhere(
status == undefined || status.trim().toUpperCase() == "ALL" || status == ""
? "1=1"
@ -126,6 +136,59 @@ export class DevelopmentRequestController extends Controller {
status: status == undefined || status == null ? "" : status.trim().toUpperCase(),
},
)
.andWhere(orgRevisionPublish ? `current_holders.orgRevisionId = :revisionId` : "1=1", {
revisionId: orgRevisionPublish?.id,
})
.andWhere(
data.root != undefined && data.root != null
? data.root[0] != null
? `current_holders.orgRootId IN (:...root)`
: `current_holders.orgRootId is null`
: "1=1",
{
root: data.root,
},
)
.andWhere(
data.child1 != undefined && data.child1 != null
? data.child1[0] != null
? `current_holders.orgChild1Id IN (:...child1)`
: `current_holders.orgChild1Id is null`
: "1=1",
{
child1: data.child1,
},
)
.andWhere(
data.child2 != undefined && data.child2 != null
? data.child2[0] != null
? `current_holders.orgChild2Id IN (:...child2)`
: `current_holders.orgChild2Id is null`
: "1=1",
{
child2: data.child2,
},
)
.andWhere(
data.child3 != undefined && data.child3 != null
? data.child3[0] != null
? `current_holders.orgChild3Id IN (:...child3)`
: `current_holders.orgChild3Id is null`
: "1=1",
{
child3: data.child3,
},
)
.andWhere(
data.child4 != undefined && data.child4 != null
? data.child4[0] != null
? `current_holders.orgChild4Id IN (:...child4)`
: `current_holders.orgChild4Id is null`
: "1=1",
{
child4: data.child4,
},
)
.andWhere(
new Brackets((qb) => {
qb.where(
@ -163,7 +226,8 @@ export class DevelopmentRequestController extends Controller {
{
keyword: `%${keyword}%`,
},
).orWhere(
)
.orWhere(
keyword != null && keyword != ""
? "developmentRequest.createdFullName LIKE :keyword"
: "1=1",
@ -177,7 +241,8 @@ export class DevelopmentRequestController extends Controller {
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
return new HttpSuccess({ data: lists, total });
const _data = lists.map((item) => ({ ...item, profile: null }));
return new HttpSuccess({ data: _data, total });
}
@Get("admin/{id}")
@ -263,7 +328,7 @@ export class DevelopmentRequestController extends Controller {
sysName: "REGISTRY_IDP",
posLevelName: profile.posLevel.posLevelName,
posTypeName: profile.posType.posTypeName,
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`
fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`,
})
.catch((error) => {
console.error("Error calling API:", error);