feat: search by field name

This commit is contained in:
Methapon2001 2024-03-22 16:04:09 +07:00
parent ff3f005b91
commit cc430a1a38

View file

@ -205,7 +205,8 @@ export class ProfileController extends Controller {
async listProfile(
@Query("page") page: number = 1,
@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({
relations: {
@ -215,15 +216,8 @@ export class ProfileController extends Controller {
relationship: true,
bloodGroup: true,
},
where: [
{ citizenId: Like(`%${keyword}%`) },
{ position: Like(`%${keyword}%`) },
{ prefix: Like(`%${keyword}%`) },
{ firstName: Like(`%${keyword}%`) },
{ lastName: Like(`%${keyword}%`) },
{ email: Like(`%${keyword}%`) },
{ telephoneNumber: Like(`%${keyword}%`) },
],
where:
searchField && searchKeyword ? [{ [searchField]: Like(`%${searchKeyword}%`) }] : undefined,
order: { createdAt: "ASC" },
skip: (page - 1) * pageSize,
take: pageSize,