@@ -17,6 +17,7 @@ import { TransactionKind } from '../../../../constants/transaction-kind';
1717import { DatabaseWithViews , getKysely , kyselyToSequelizeModels } from '../../../../lib/kysely' ;
1818import { EntityShortIdPrefix , isEntityPublicId } from '../../../../lib/permalink/entity-map' ;
1919import { buildSearchConditions } from '../../../../lib/sql-search' ;
20+ import { removeDiacritics } from '../../../../lib/string-utils' ;
2021import models , { Collective , ManualPaymentProvider , Op , PaymentMethod , Tier , User } from '../../../../models' ;
2122import { checkScope } from '../../../common/scope-check' ;
2223import { Forbidden , NotFound , Unauthorized } from '../../../errors' ;
@@ -521,7 +522,7 @@ export const OrdersCollectionResolver = async (args: OrdersCollectionArgsType, r
521522 . select ( 'Orders.id' )
522523 . where ( 'Orders.deletedAt' , 'is' , null )
523524 . $if ( ! ! args . searchTerm , qb => {
524- return qb . where ( ( { or, eb } ) => {
525+ return qb . where ( ( { fn , or, eb } ) => {
525526 if ( isFinite ( Number ( args . searchTerm ) ) && isInteger ( Number ( args . searchTerm ) ) ) {
526527 ors . push ( eb ( 'Orders.id' , '=' , Number ( args . searchTerm ) ) ) ;
527528 }
@@ -535,9 +536,17 @@ export const OrdersCollectionResolver = async (args: OrdersCollectionArgsType, r
535536 ors . push ( eb ( 'Orders.FromCollectiveId' , '=' , collectiveBySearchTerm . id ) ) ;
536537 }
537538
538- ors . push ( eb ( 'Orders.description' , 'ilike' , `%${ args . searchTerm } %` ) ) ;
539+ const searchTermNoDiacrits =
540+ typeof args . searchTerm === 'string' ? removeDiacritics ( args . searchTerm ) : args . searchTerm ;
541+ ors . push ( eb ( fn < string > ( 'unaccent' , [ 'Orders.description' ] ) , 'ilike' , `%${ searchTermNoDiacrits } %` ) ) ;
539542 ors . push ( eb ( sql `"Orders".data->>'ponumber'` , 'ilike' , `%${ args . searchTerm } %` ) ) ;
540- ors . push ( eb ( sql `"Orders".data#>>'{fromAccountInfo,name}'` , 'ilike' , `%${ args . searchTerm } %` ) ) ;
543+ ors . push (
544+ eb (
545+ fn < string > ( 'unaccent' , [ sql `"Orders".data#>>'{fromAccountInfo,name}'` ] ) ,
546+ 'ilike' ,
547+ `%${ searchTermNoDiacrits } %` ,
548+ ) ,
549+ ) ;
541550 ors . push ( eb ( sql `"Orders".data#>>'{fromAccountInfo,email}'` , 'ilike' , `%${ args . searchTerm } %` ) ) ;
542551 ors . push (
543552 eb ( 'Orders.tags' , '&&' , sql < string [ ] > `ARRAY[${ args . searchTerm . toLocaleLowerCase ( ) } ]::varchar[]` ) ,
@@ -915,8 +924,8 @@ export const OrdersCollectionResolver = async (args: OrdersCollectionArgsType, r
915924 const { limit = 10 , offset = 0 , searchTerm } = subArgs ;
916925
917926 const searchConditions = buildSearchConditions ( searchTerm , {
918- slugFields : [ 'slug' ] ,
919- textFields : [ 'name' ] ,
927+ slugFields : [ 'Collective. slug' ] ,
928+ textFields : [ 'Collective. name' ] ,
920929 publicIdFields : [ { field : 'publicId' , prefix : EntityShortIdPrefix . Collective } ] ,
921930 } ) ;
922931
0 commit comments