1- import { constructPrefixTsQuery } from 'shared/helpers/search'
2- import {
3- from ,
4- join ,
5- limit ,
6- orderBy ,
7- renderSql ,
8- select ,
9- where ,
10- } from 'shared/supabase/sql-builder'
11- import { type APIHandler } from './helpers/endpoint'
12- import { convertUser } from 'common/supabase/users'
13- import { createSupabaseDirectClient } from 'shared/supabase/init'
14- import { toUserAPIResponse } from 'common/api/user-types'
15- import { uniqBy } from 'lodash'
1+ import { constructPrefixTsQuery } from 'shared/helpers/search'
2+ import { from , limit , orderBy , renderSql , select , where , } from 'shared/supabase/sql-builder'
3+ import { type APIHandler } from './helpers/endpoint'
4+ import { convertUser } from 'common/supabase/users'
5+ import { createSupabaseDirectClient } from 'shared/supabase/init'
6+ import { toUserAPIResponse } from 'common/api/user-types'
7+ import { uniqBy } from 'lodash'
168
17- export const searchUsers : APIHandler < 'search-users' > = async ( props , auth ) => {
18- const { term, page, limit } = props
9+ export const searchUsers : APIHandler < 'search-users' > = async ( props , _auth ) => {
10+ const { term, page, limit} = props
1911
2012 const pg = createSupabaseDirectClient ( )
2113
2214 const offset = page * limit
2315 // const userId = auth?.uid
2416 // const searchFollowersSQL = getSearchUserSQL({ term, offset, limit, userId })
25- const searchAllSQL = getSearchUserSQL ( { term, offset, limit } )
17+ const searchAllSQL = getSearchUserSQL ( { term, offset, limit} )
2618 const [ all ] = await Promise . all ( [
2719 // pg.map(searchFollowersSQL, null, convertUser),
2820 pg . map ( searchAllSQL , null , convertUser ) ,
@@ -39,7 +31,7 @@ function getSearchUserSQL(props: {
3931 limit : number
4032 userId ?: string // search only this user's followers
4133} ) {
42- const { term } = props
34+ const { term} = props
4335
4436 return renderSql (
4537 // userId
@@ -50,21 +42,21 @@ function getSearchUserSQL(props: {
5042 // where('user_follows.user_id = $1', [userId]),
5143 // ]
5244 // :
53- [ select ( '*' ) , from ( 'users' ) ] ,
45+ [ select ( '*' ) , from ( 'users' ) ] ,
5446 term
5547 ? [
56- where (
57- `name_username_vector @@ websearch_to_tsquery('english', $1)
48+ where (
49+ `name_username_vector @@ websearch_to_tsquery('english', $1)
5850 or name_username_vector @@ to_tsquery('english', $2)` ,
59- [ term , constructPrefixTsQuery ( term ) ]
60- ) ,
51+ [ term , constructPrefixTsQuery ( term ) ]
52+ ) ,
6153
62- orderBy (
63- `ts_rank(name_username_vector, websearch_to_tsquery($1)) desc,
54+ orderBy (
55+ `ts_rank(name_username_vector, websearch_to_tsquery($1)) desc,
6456 data->>'lastBetTime' desc nulls last` ,
65- [ term ]
66- ) ,
67- ]
57+ [ term ]
58+ ) ,
59+ ]
6860 : orderBy ( `data->'creatorTraders'->'allTime' desc nulls last` ) ,
6961 limit ( props . limit , props . offset )
7062 )
0 commit comments