1
1
import type { Prisma } from '@prisma/client'
2
2
import { PrismaClient } from '@prisma/client'
3
3
import type { Tool , ToolExample } from '@/lib/types'
4
+ import { FeaturedTools } from '@/lib/featured'
4
5
5
6
const prisma = new PrismaClient ( )
6
7
const all = - 1
@@ -127,19 +128,30 @@ export async function getToolsForQuery(query: string, page: number, pageSize: nu
127
128
skip : skip > 0 && page != all ? skip : undefined ,
128
129
} )
129
130
131
+ const featured : Record < string , Tool [ ] > = { }
130
132
const tools : Record < string , Tool [ ] > = { }
131
133
132
134
// Add them to the results so that the ones with the query in the reference come first
133
135
for ( const entry of toolEntriesWithReference ) {
134
136
const parsedTool = entry . content as Tool [ ]
135
- tools [ entry . reference ] = tools [ entry . reference ] || [ ]
136
- tools [ entry . reference ] . push ( ...parsedTool )
137
+ if ( FeaturedTools . has ( entry . reference ) ) {
138
+ featured [ entry . reference ] = featured [ entry . reference ] || [ ]
139
+ featured [ entry . reference ] . push ( ...parsedTool )
140
+ } else {
141
+ tools [ entry . reference ] = tools [ entry . reference ] || [ ]
142
+ tools [ entry . reference ] . push ( ...parsedTool )
143
+ }
137
144
}
138
145
139
146
for ( const entry of toolEntriesWithDescription ) {
140
147
const parsedTool = entry . content as Tool [ ]
141
- tools [ entry . reference ] = tools [ entry . reference ] || [ ]
142
- tools [ entry . reference ] . push ( ...parsedTool )
148
+ if ( FeaturedTools . has ( entry . reference ) ) {
149
+ featured [ entry . reference ] = featured [ entry . reference ] || [ ]
150
+ featured [ entry . reference ] . push ( ...parsedTool )
151
+ } else {
152
+ tools [ entry . reference ] = tools [ entry . reference ] || [ ]
153
+ tools [ entry . reference ] . push ( ...parsedTool )
154
+ }
143
155
}
144
156
145
157
const totalCount = await prisma . toolEntry . count ( {
@@ -161,5 +173,5 @@ export async function getToolsForQuery(query: string, page: number, pageSize: nu
161
173
}
162
174
} )
163
175
164
- return { tools, totalCount }
176
+ return { tools : { ... featured , ... tools } , totalCount }
165
177
}
0 commit comments