Skip to content

Commit

Permalink
created api for querying users
Browse files Browse the repository at this point in the history
  • Loading branch information
Swarga-codes committed May 23, 2024
1 parent eda26e7 commit b549090
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions app/api/users/route.ts → app/api/users/[searchQuery]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ export async function GET(req:NextRequest) {
if (!decodedToken.success) return NextResponse.json(decodedToken, { status: 401 });
const email = decodedToken?.email;
await connectDb();
const getUsers=await USER.find({isVerified:true}).select('-password -verifyOtp -verifyOtpExpiry')
const filterTheRequestedUser=getUsers.filter(user=>user.email!==email)
return NextResponse.json({success:true,message:'Fetched users successfully',users:filterTheRequestedUser},{status:200})
const splitUrl=req.url.split('/')
const searchQuery=splitUrl[splitUrl.length-1];
const getUsers=await USER.find({isVerified:true,email:{$ne:email}, $or:[
{username:{$regex:searchQuery,$options:'i'}},
{email:{$regex:searchQuery,$options:'i'}}
]}).select('-password -verifyOtp -verifyOtpExpiry')
return NextResponse.json({success:true,message:'Fetched users successfully',users:getUsers},{status:200})
} catch (error) {
console.log(error)
return NextResponse.json({success:false,message:'Could not fetch users, try again!'},{status:500})
Expand Down
1 change: 1 addition & 0 deletions app/memories/[memoryId]/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Page({params:{memoryId}}) {
}

}

useEffect(()=>{
fetchMemoryDetails()
},[])
Expand Down

0 comments on commit b549090

Please sign in to comment.