(request: NextRequest)
| 22 | }; |
| 23 | |
| 24 | export async function GET(request: NextRequest) { |
| 25 | const { searchParams } = new URL(request.url); |
| 26 | const searchQuery = searchParams.get('q'); |
| 27 | |
| 28 | if (searchQuery && searchQuery.length > 2) { |
| 29 | const value: TSearchedVideos[] = await cache.get( |
| 30 | 'getAllVideosForSearch', |
| 31 | [], |
| 32 | ); |
| 33 | |
| 34 | if (value) { |
| 35 | return NextResponse.json(fuzzySearch(value, searchQuery)); |
| 36 | } |
| 37 | |
| 38 | const allVideos = await db.content.findMany({ |
| 39 | where: { |
| 40 | type: 'video', |
| 41 | hidden: false, |
| 42 | }, |
| 43 | select: { |
| 44 | id: true, |
| 45 | parentId: true, |
| 46 | title: true, |
| 47 | parent: { |
| 48 | select: { |
| 49 | courses: true, |
| 50 | }, |
| 51 | }, |
| 52 | }, |
| 53 | }); |
| 54 | |
| 55 | cache.set('getAllVideosForSearch', [], allVideos, 24 * 60 * 60); |
| 56 | |
| 57 | return NextResponse.json(fuzzySearch(allVideos, searchQuery)); |
| 58 | } |
| 59 | |
| 60 | return NextResponse.json({}, { status: 400 }); |
| 61 | } |
nothing calls this directly
no test coverage detected