From 0788f3a1ee7650a138e04029d77a760fbcdf6c32 Mon Sep 17 00:00:00 2001 From: Claudemir Todo Bom Date: Sun, 1 Dec 2024 10:45:26 -0300 Subject: [PATCH] search contacts ignoring accents - fix #219 --- .../ContactServices/ListContactsService.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/services/ContactServices/ListContactsService.ts b/backend/src/services/ContactServices/ListContactsService.ts index e9a27c53..5ac0df61 100644 --- a/backend/src/services/ContactServices/ListContactsService.ts +++ b/backend/src/services/ContactServices/ListContactsService.ts @@ -18,16 +18,23 @@ const ListContactsService = async ({ pageNumber = "1", companyId }: Request): Promise => { + const normalizedSearchParam = searchParam.toLowerCase().trim(); const whereCondition = { [Op.or]: [ { name: Sequelize.where( - Sequelize.fn("LOWER", Sequelize.col("name")), - "LIKE", - `%${searchParam.toLowerCase().trim()}%` + Sequelize.fn( + "LOWER", + Sequelize.fn("UNACCENT", Sequelize.col("name")) + ), + { + [Op.like]: Sequelize.literal( + `'%' || UNACCENT('${normalizedSearchParam}') || '%'` + ) + } ) }, - { number: { [Op.like]: `%${searchParam.toLowerCase().trim()}%` } } + { number: { [Op.like]: `%${normalizedSearchParam}%` } } ], companyId: { [Op.eq]: companyId