feat: search by field name
This commit is contained in:
parent
ff3f005b91
commit
cc430a1a38
1 changed files with 4 additions and 10 deletions
|
|
@ -205,7 +205,8 @@ export class ProfileController extends Controller {
|
||||||
async listProfile(
|
async listProfile(
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@Query("pageSize") pageSize: number = 10,
|
@Query("pageSize") pageSize: number = 10,
|
||||||
@Query("keyword") keyword: string = "",
|
@Query() searchField?: "firstName" | "lastName" | "citizenId" | "position",
|
||||||
|
@Query() searchKeyword: string = "",
|
||||||
) {
|
) {
|
||||||
const [record, total] = await this.profileRepo.findAndCount({
|
const [record, total] = await this.profileRepo.findAndCount({
|
||||||
relations: {
|
relations: {
|
||||||
|
|
@ -215,15 +216,8 @@ export class ProfileController extends Controller {
|
||||||
relationship: true,
|
relationship: true,
|
||||||
bloodGroup: true,
|
bloodGroup: true,
|
||||||
},
|
},
|
||||||
where: [
|
where:
|
||||||
{ citizenId: Like(`%${keyword}%`) },
|
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
|
||||||
{ position: Like(`%${keyword}%`) },
|
|
||||||
{ prefix: Like(`%${keyword}%`) },
|
|
||||||
{ firstName: Like(`%${keyword}%`) },
|
|
||||||
{ lastName: Like(`%${keyword}%`) },
|
|
||||||
{ email: Like(`%${keyword}%`) },
|
|
||||||
{ telephoneNumber: Like(`%${keyword}%`) },
|
|
||||||
],
|
|
||||||
order: { createdAt: "ASC" },
|
order: { createdAt: "ASC" },
|
||||||
skip: (page - 1) * pageSize,
|
skip: (page - 1) * pageSize,
|
||||||
take: pageSize,
|
take: pageSize,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue