diff --git a/app/api/event1/deleteTeam/[teamId]/route.js b/app/api/event1/deleteTeam/[teamId]/route.js index 9c3ce08..b8b570c 100644 --- a/app/api/event1/deleteTeam/[teamId]/route.js +++ b/app/api/event1/deleteTeam/[teamId]/route.js @@ -1,6 +1,7 @@ import { connectMongoDB } from "@/lib/mongodb"; -import { TeamModel } from "@/models/TeamDetails"; -import { TeamToken } from "@/models/event1TeamToken"; +import { Event1 } from "@/models/event1.model"; + +import { event1TeamToken } from "@/models/event1TeamToken"; import { Users } from "@/models/user.model"; import { getTokenDetails } from "@/utils/authuser"; import { getToken } from "next-auth/jwt"; @@ -19,7 +20,7 @@ export async function POST(req,{params}){ const teamId=params.teamId; - const team = await TeamModel.findById({ _id: teamId }); + const team = await Event1.findById({ _id: teamId }); console.log(team); if (!team) { @@ -38,17 +39,17 @@ export async function POST(req,{params}){ return NextResponse.json({ message: "Team Size more than 1", status: 200 }); } - await TeamModel.findOneAndDelete({ + await Event1.findOneAndDelete({ _id: teamId, }); - await TeamToken.findOneAndDelete({ + await event1TeamToken.findOneAndDelete({ teamId: teamId, }); await Users.findByIdAndUpdate( { _id: userId }, - { teamId: null, teamRole: null } + { event1TeamId: null, event1TeamRole: null } ); diff --git a/app/api/event1/getTeamData/route.js b/app/api/event1/getTeamData/route.js index 9a901e7..ca136be 100644 --- a/app/api/event1/getTeamData/route.js +++ b/app/api/event1/getTeamData/route.js @@ -24,6 +24,7 @@ export async function GET(req) { const teamId = user.event1TeamId; const team = await Event1.findById(teamId).populate('members'); + console.log("^^^^^^",team); if (!team) { return NextResponse.json({ message: 'Team is not there ' }); } diff --git a/app/api/event1/getTeamViaToken/route.js b/app/api/event1/getTeamViaToken/route.js index 65747c8..32be7bb 100644 --- a/app/api/event1/getTeamViaToken/route.js +++ b/app/api/event1/getTeamViaToken/route.js @@ -10,8 +10,9 @@ export async function POST(req) { const { teamCode } = await req.json(); console.log(teamCode); const team = await event1TeamToken.findOne({ token: teamCode }); + if (!team) { - return NextResponse.json({ error: "Team not found" }); + return NextResponse.json({ error: "Token not found" }); } const teamDetails = await Event1.findById(team.teamId); diff --git a/app/api/event1/leaveTeam/route.js b/app/api/event1/leaveTeam/route.js index 68cc44f..63a4ea7 100644 --- a/app/api/event1/leaveTeam/route.js +++ b/app/api/event1/leaveTeam/route.js @@ -5,7 +5,7 @@ import { NextResponse } from 'next/server'; import { getToken } from 'next-auth/jwt'; import { getTokenDetails } from '../../../../utils/authuser'; - +/// export async function POST(req) { try { await connectMongoDB(); @@ -16,6 +16,7 @@ export async function POST(req) { console.log(userId); const user = await Users.findById(userId); + console.log("*********",user); if (user.event1TeamRole != 1) { return NextResponse.json({ diff --git a/app/api/event1/removeMember/[teamId]/route.js b/app/api/event1/removeMember/[teamId]/route.js index caddf85..76c88a7 100644 --- a/app/api/event1/removeMember/[teamId]/route.js +++ b/app/api/event1/removeMember/[teamId]/route.js @@ -1,59 +1,70 @@ import { connectMongoDB } from "@/lib/mongodb"; -import { TeamModel } from "@/models/TeamDetails"; -import { UsersDetails } from "@/models/Userdetails"; + + import { NextResponse } from "next/server"; +import { Users } from "@/models/user.model"; -import UserDetails from "@/components/userDetails"; import { getToken } from "next-auth/jwt"; import { getTokenDetails } from "../../../../../utils/authuser"; +import { Event1 } from "@/models/event1.model"; export async function POST(req, { params }) { try { + console.log("me idhr hu"); await connectMongoDB(); const token = await getToken({req}) const auth = token ? token.accessTokenFromBackend : null let userId = await getTokenDetails(auth); + const user1=await Users.findById(userId); + console.log("]]]]]]",user1); + const teamId = params.teamId; - const team = await TeamModel.findById({ _id: teamId }); - console.log(team); + const team = await Event1.findById({ _id: teamId }); + console.log("______",team); if (!team) { - return res.status(401).json({ - message: "Invalid TeamId to remove", - }); + console.log("here1"); + return NextResponse.json({ message: "Invalid teamId to remove", status: 200 }); } - const userToRemove = await UserDetails.findById({ _id: userId }); + const userToRemove = await Users.findById({ _id: userId }); if (!userToRemove) { + console.log("here2"); return NextResponse.json({ message: "UserID is invalid", status: 200 }); } if (team.teamLeaderId.toString() !== userId) { + console.log("here3"); return NextResponse.json({ + message: "User doesn't belong to the team or user isn't a leader", status: 200, }); } if ( - userToRemove.teamId == null || - userToRemove.teamId.toString() !== teamId + userToRemove. + event1TeamId == null || + userToRemove. + event1TeamId.toString() !== teamId ) { - return res.status(401).json({ + console.log("here88") + return NextResponse.json({ message: "User to remove and TeamId didnt Match", }); } - - await UsersDetails.findOneAndUpdate( - { _id: req.body.userId }, - { teamId: null, teamRole: -1 } + console.log("================") + await Users.findOneAndUpdate( + { _id: userId }, + { event1TeamId: null, event1TeamRole + : -1 } ); //updating team - await TeamModel.findOneAndUpdate( - { _id: req.params.teamId }, + await Event1.findOneAndUpdate( + { _id: teamId }, { $pull: { members: req.body.userId } } ); diff --git a/app/events/event1/leaderDash/page.jsx b/app/events/event1/leaderDash/page.jsx index 46aec57..a6ba51d 100644 --- a/app/events/event1/leaderDash/page.jsx +++ b/app/events/event1/leaderDash/page.jsx @@ -110,9 +110,10 @@ export default function LeaderDashboard() { setPopUpForDelete(!popUpForDelete); } function removeMember(id) { + console.log("||||||",teamId); setRemove((prev) => !prev); setIsLoading(true); - fetch('/team/remove/' + teamId, { + fetch(`/api/event1/removeMember/${teamId}`, { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -125,7 +126,7 @@ export default function LeaderDashboard() { }) .then((res) => res.json()) .then((data) => { - location.reload(); + //location.reload(); setIsLoading(false); }) .then(() => { @@ -141,7 +142,7 @@ export default function LeaderDashboard() { } setIsLoading(true); setDeleted(!deleted); - fetch('/team/deleteTeam/' + teamId, { + fetch(`/api/event1/deleteTeam/${teamId}` , { method: 'POST', headers: { 'Content-Type': 'application/json', @@ -152,7 +153,7 @@ export default function LeaderDashboard() { .then((res) => res.json()) .then((data) => {}) .then(() => { - router.push('/makeTeam'); + router.push('/events/event1/makeTeam'); toast.success('Team Deleted.'); setIsLoading(false); }) diff --git a/app/events/event1/memberDash/page.jsx b/app/events/event1/memberDash/page.jsx index d7fc1fc..169872b 100644 --- a/app/events/event1/memberDash/page.jsx +++ b/app/events/event1/memberDash/page.jsx @@ -113,7 +113,7 @@ const TeamPage = () => { console.log('data', data) if(data.error == false) { setIsLoading(true); - router.push('/makeTeam') + router.push('/events/event/makeTeam') } }) } diff --git a/components/Navbar.jsx b/components/Navbar.jsx index 5cd33e8..f3e7aee 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -88,6 +88,7 @@ const Navbar = () => {