diff --git a/src/db/util/conditions.ts b/src/db/util/conditions.ts index 175008cd..23dff554 100644 --- a/src/db/util/conditions.ts +++ b/src/db/util/conditions.ts @@ -77,11 +77,11 @@ namespace PropertyConditions { // Simple binary operator conditions - export type LikeCondition = { - [Op.LIKE]: T & string; + export type LikeCondition = { + [Op.LIKE]: string; }; - export type ILikeCondition = { - [Op.ILIKE]: T & string; + export type ILikeCondition = { + [Op.ILIKE]: string; }; export type LtCondition = { [Op.LT]: T; @@ -104,8 +104,8 @@ namespace PropertyConditions { | NotInCondition | IsNullCondition | BetweenCondition - | LikeCondition - | ILikeCondition + | LikeCondition + | ILikeCondition | LtCondition | LteCondition | GtCondition @@ -138,12 +138,12 @@ namespace PropertyConditions { export const isLikeCondition = ( condition: Condition - ): condition is LikeCondition => + ): condition is LikeCondition => Object.prototype.hasOwnProperty.call(condition, Op.LIKE); export const isILikeCondition = ( condition: Condition - ): condition is ILikeCondition => + ): condition is ILikeCondition => Object.prototype.hasOwnProperty.call(condition, Op.ILIKE); export const isLtCondition = ( @@ -282,13 +282,15 @@ export const prepareCondition = propertyCondition[Op.BETWEEN][1], ]); } else if (PropertyConditions.isLikeCondition(propertyCondition)) { - builder.where(property as string, 'like', propertyCondition[Op.LIKE]); + builder.whereRaw('unaccent(:column:) like unaccent(:value)', { + column: String(property), + value: propertyCondition[Op.LIKE], + }); } else if (PropertyConditions.isILikeCondition(propertyCondition)) { - builder.where( - property as string, - 'ilike', - propertyCondition[Op.ILIKE] - ); + builder.whereRaw('unaccent(:column:) ilike unaccent(:value)', { + column: String(property), + value: propertyCondition[Op.ILIKE], + }); } else if (PropertyConditions.isLtCondition(propertyCondition)) { builder.where(property, '<', propertyCondition[Op.LT] as any); } else if (PropertyConditions.isLteCondition(propertyCondition)) {