updated search keyword
This commit is contained in:
parent
465ff35a4c
commit
76a3a53385
1 changed files with 79 additions and 31 deletions
|
|
@ -20,6 +20,7 @@ import { setLogDataDiff } from "../interfaces/utils";
|
||||||
import { Personal, PostPersonal } from "../entities/Personal";
|
import { Personal, PostPersonal } from "../entities/Personal";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { Assign } from "../entities/Assign";
|
import { Assign } from "../entities/Assign";
|
||||||
|
import { Brackets } from "typeorm";
|
||||||
|
|
||||||
@Route("api/v1/probation/personal")
|
@Route("api/v1/probation/personal")
|
||||||
@Tags("Personal")
|
@Tags("Personal")
|
||||||
|
|
@ -101,6 +102,7 @@ export class PersonalController extends Controller {
|
||||||
@Get("list")
|
@Get("list")
|
||||||
async ListPersonal(
|
async ListPersonal(
|
||||||
@Query() status: string = "",
|
@Query() status: string = "",
|
||||||
|
@Query() keyword: string = "",
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
|
|
@ -133,12 +135,39 @@ export class PersonalController extends Controller {
|
||||||
conditions.child4 = _data.child4;
|
conditions.child4 = _data.child4;
|
||||||
}
|
}
|
||||||
|
|
||||||
const [lists, total] = await this.personalRepository.findAndCount({
|
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||||
order: { createdAt: "DESC" },
|
|
||||||
where: conditions,
|
const [lists, total] = await AppDataSource.getRepository(Personal)
|
||||||
skip: (page - 1) * pageSize,
|
.createQueryBuilder("personal")
|
||||||
take: pageSize,
|
.where(conditions)
|
||||||
|
.andWhere(
|
||||||
|
new Brackets((qb) => {
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword
|
||||||
|
? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'`
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
});
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", {
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.orderBy("updatedAt", "DESC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
if (!lists) {
|
if (!lists) {
|
||||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้");
|
||||||
|
|
@ -146,32 +175,51 @@ export class PersonalController extends Controller {
|
||||||
|
|
||||||
let result: any = [];
|
let result: any = [];
|
||||||
|
|
||||||
await Promise.all(
|
for (let i = 0; i < lists.length; i++) {
|
||||||
lists.map(async (item, index) => {
|
|
||||||
const probation_no = await this.assignRepository.count({
|
const probation_no = await this.assignRepository.count({
|
||||||
where: {
|
where: { personal_id: lists[i].personal_id },
|
||||||
personal_id: item.personal_id,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await result.push({
|
await result.push({
|
||||||
personal_id: item.personal_id,
|
personal_id: lists[i].personal_id,
|
||||||
ordering: index + 1,
|
ordering: i + 1,
|
||||||
name: item.prefixName + item.firstName + " " + item.lastName,
|
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
||||||
idcard: item.idcard,
|
idcard: lists[i].idcard,
|
||||||
prefixName: item.prefixName,
|
position_line: lists[i].positionName,
|
||||||
firstName: item.firstName,
|
position_level: lists[i].positionLevelName,
|
||||||
lastName: item.lastName,
|
position_type: lists[i].positionTypeName,
|
||||||
position_line: item.positionName,
|
organization: lists[i].organization,
|
||||||
position_level: item.positionLevelName,
|
|
||||||
position_type: item.positionTypeName,
|
|
||||||
organization: item.organization,
|
|
||||||
probation_no: probation_no,
|
probation_no: probation_no,
|
||||||
order_number: item.order_number,
|
order_number: lists[i].order_number,
|
||||||
probation_status: item.probation_status,
|
probation_status: lists[i].probation_status,
|
||||||
});
|
});
|
||||||
}),
|
}
|
||||||
);
|
// await Promise.all(
|
||||||
|
// lists.map(async (item, index) => {
|
||||||
|
// const probation_no = await this.assignRepository.count({
|
||||||
|
// where: {
|
||||||
|
// personal_id: item.personal_id,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
|
// await result.push({
|
||||||
|
// personal_id: item.personal_id,
|
||||||
|
// ordering: index + 1,
|
||||||
|
// name: item.prefixName + item.firstName + " " + item.lastName,
|
||||||
|
// idcard: item.idcard,
|
||||||
|
// // prefixName: item.prefixName,
|
||||||
|
// // firstName: item.firstName,
|
||||||
|
// // lastName: item.lastName,
|
||||||
|
// position_line: item.positionName,
|
||||||
|
// position_level: item.positionLevelName,
|
||||||
|
// position_type: item.positionTypeName,
|
||||||
|
// organization: item.organization,
|
||||||
|
// probation_no: probation_no,
|
||||||
|
// order_number: item.order_number,
|
||||||
|
// probation_status: item.probation_status,
|
||||||
|
// });
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
return new HttpSuccess({ data: result, total: total });
|
return new HttpSuccess({ data: result, total: total });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue