Skip to content

Commit

Permalink
search contacts ignoring accents - fix #219
Browse files Browse the repository at this point in the history
  • Loading branch information
allgood committed Dec 1, 2024
1 parent 8c8521d commit 0788f3a
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions backend/src/services/ContactServices/ListContactsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,23 @@ const ListContactsService = async ({
pageNumber = "1",
companyId
}: Request): Promise<Response> => {
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
Expand Down

0 comments on commit 0788f3a

Please sign in to comment.