From 81c9db66e5d5042e9f501608d93cecbff28c11d3 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 16 Aug 2024 12:06:37 +0700 Subject: [PATCH] fix find fullName --- src/controllers/ProfileController.ts | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6faf820f..daf35527 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -4191,7 +4191,8 @@ export class ProfileController extends Controller { keyword?: string; }, ) { - const [firstName, lastName] = body.keyword ? body.keyword.split(" ") : ["", ""]; + let conditionFullName = + "CONCAT(profile.prefix, profile.firstName, ' ', profile.lastName) LIKE :keyword"; const [findProfile, total] = await AppDataSource.getRepository(Profile) .createQueryBuilder("profile") .leftJoinAndSelect("profile.posLevel", "posLevel") @@ -4223,16 +4224,9 @@ export class ProfileController extends Controller { .orWhere(`posType.posTypeName LIKE :keyword`, { keyword: `%${body.keyword}%`, }) - .orWhere( - new Brackets((qb) => { - if (body.keyword) { - qb.where(`profile.firstName LIKE :firstName`, { firstName: `%${firstName}%` }).orWhere( - `profile.lastName LIKE :lastName`, - { lastName: `%${lastName}%` }, - ); - } - }), - ) + .orWhere(conditionFullName, { + keyword: `%${body.keyword}%`, + }) .orderBy("profile.citizenId", "ASC") .skip((body.page - 1) * body.pageSize) .take(body.pageSize)