From 700e6b14d107383ce489f6a125798691944e2122 Mon Sep 17 00:00:00 2001 From: Satyam Shubham <57027429+ItsFlash10@users.noreply.github.com> Date: Sat, 5 Oct 2024 03:15:28 +0530 Subject: [PATCH] feat/search: Added search bar and other minor ui fix (#1176) * feat/search: Added search bar and other minor ui fix * feat/search: Fixed search api result * feat/search: minor fix * Update Sidebar.tsx tried the GUI conflict resolver xD * Update Sidebar.tsx --- src/app/api/search/route.ts | 16 ++++++++++++++++ src/app/courses/[courseId]/layout.tsx | 6 +++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/app/api/search/route.ts b/src/app/api/search/route.ts index 84c9643c4..2c16770f9 100644 --- a/src/app/api/search/route.ts +++ b/src/app/api/search/route.ts @@ -3,6 +3,8 @@ import db from '@/db'; import { CourseContent } from '@prisma/client'; import Fuse from 'fuse.js'; import { NextRequest, NextResponse } from 'next/server'; +import { getServerSession } from 'next-auth'; +import { authOptions } from '@/lib/auth'; export type TSearchedVideos = { id: number; @@ -24,6 +26,7 @@ const fuzzySearch = (videos: TSearchedVideos[], searchQuery: string) => { export async function GET(request: NextRequest) { const { searchParams } = new URL(request.url); const searchQuery = searchParams.get('q'); + const session = await getServerSession(authOptions); if (searchQuery && searchQuery.length > 2) { const value: TSearchedVideos[] = await cache.get( @@ -39,6 +42,19 @@ export async function GET(request: NextRequest) { where: { type: 'video', hidden: false, + parent: { + courses: { + some: { + course: { + purchasedBy: { + some: { + userId: session?.user?.id, + }, + }, + }, + }, + }, + }, }, select: { id: true, diff --git a/src/app/courses/[courseId]/layout.tsx b/src/app/courses/[courseId]/layout.tsx index f134db9b4..e6c279ddd 100644 --- a/src/app/courses/[courseId]/layout.tsx +++ b/src/app/courses/[courseId]/layout.tsx @@ -1,4 +1,5 @@ import { QueryParams } from '@/actions/types'; +import SearchBar from '@/components/search/SearchBar'; import { Sidebar } from '@/components/Sidebar'; import { getFullCourseContent } from '@/db/course'; import { authOptions } from '@/lib/auth'; @@ -49,7 +50,10 @@ const Layout = async ({ return (