@@ -21,6 +21,7 @@ export type UserTicketSearch = {
2121 email ?: string ;
2222 name ?: string ;
2323 tags ?: AllowedUserTags [ ] ;
24+ text ?: string ;
2425} ;
2526
2627type SortableFields = "createdAt" | "name" ;
@@ -31,7 +32,7 @@ const getSearchUsersQuery = (
3132 search : UserTicketSearch = { } ,
3233 sort ?: UserFetcherSort ,
3334) => {
34- const { userIds, userName, name, email, tags } = search ;
35+ const { userIds, userName, name, email, tags, text } = search ;
3536
3637 const wheres : SQL [ ] = [ ] ;
3738 const query = DB . select ( ) . from ( usersSchema ) ;
@@ -78,6 +79,23 @@ const getSearchUsersQuery = (
7879 ilike ( usersSchema . username , sanitizeForLikeSearch ( userName ) ) ;
7980 }
8081
82+ if ( text ) {
83+ const spacedText = text . split ( " " ) . map ( ( el ) => el . trim ( ) ) ;
84+
85+ const orChecks = or (
86+ ...spacedText . map ( ( word ) =>
87+ ilike ( usersSchema . name , sanitizeForLikeSearch ( word ) ) ,
88+ ) ,
89+ ilike ( usersSchema . lastName , sanitizeForLikeSearch ( text ) ) ,
90+ ilike ( usersSchema . username , sanitizeForLikeSearch ( text ) ) ,
91+ ilike ( usersSchema . email , sanitizeForLikeSearch ( text ) ) ,
92+ ) ;
93+
94+ if ( orChecks ) {
95+ wheres . push ( orChecks ) ;
96+ }
97+ }
98+
8199 const orderBy : SQL < unknown > [ ] = [ ] ;
82100
83101 if ( sort ) {
0 commit comments