File tree Expand file tree Collapse file tree 1 file changed +18
-6
lines changed
Expand file tree Collapse file tree 1 file changed +18
-6
lines changed Original file line number Diff line number Diff line change 11import { DB , SCHEMA } from "@/db" ;
22import { createTRPCRouter , publicProcedure } from "@/trpc" ;
3- import { and , eq , ilike , sql } from "drizzle-orm" ;
3+ import { eq , sql , ilike } from "drizzle-orm" ;
44import { z } from "zod/v4" ;
55
66const GROUPS = SCHEMA . TG . groups ;
@@ -13,15 +13,27 @@ export default createTRPCRouter({
1313 search : publicProcedure
1414 . input (
1515 z . object ( {
16- query : z . string ( ) ,
16+ query : z . string ( ) . min ( 1 ) . max ( 100 ) ,
17+ limit : z . number ( ) . min ( 1 ) . max ( 20 ) . default ( 6 ) ,
1718 } ) ,
1819 )
1920 . query ( async ( { input } ) => {
20- return await DB . select ( )
21+ const { query, limit } = input ;
22+
23+ const likeQuery = query . split ( " " ) . join ( "%" )
24+ const results = await DB . select ( {
25+ telegramId : GROUPS . telegramId ,
26+ title : GROUPS . title ,
27+ link : GROUPS . link ,
28+ } )
2129 . from ( GROUPS )
22- . where ( ( t ) =>
23- and ( ...input . query . split ( " " ) . map ( ( q ) => ilike ( t . title , `%${ q } %` ) ) ) ,
24- ) ;
30+ . where ( t => ilike ( t . title , `%${ likeQuery } %` ) )
31+ . limit ( limit ) ;
32+
33+ return {
34+ groups : results ,
35+ count : results . length ,
36+ } ;
2537 } ) ,
2638
2739 getById : publicProcedure
You can’t perform that action at this time.
0 commit comments