-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/PranavMurali-Coder/Esummit24
- Loading branch information
Showing
13 changed files
with
362 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,58 @@ | ||
import { connectMongoDB } from "@/lib/mongodb"; | ||
import { TeamModel } from "@/models/TeamDetails"; | ||
import { Users } from "@/models/user.model"; | ||
import { NextResponse } from "next/server"; | ||
import { connectMongoDB } from '@/lib/mongodb'; | ||
import { Event1 } from '@/models/event1.model'; | ||
import { Users } from '@/models/user.model'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
import { getToken } from "next-auth/jwt"; | ||
import { getTokenDetails } from "../../../../utils/authuser"; | ||
import { getToken } from 'next-auth/jwt'; | ||
import { getTokenDetails } from '../../../../utils/authuser'; | ||
|
||
|
||
export async function POST(req){ | ||
try{ | ||
export async function POST(req) { | ||
try { | ||
await connectMongoDB(); | ||
|
||
const token = await getToken({req}) | ||
const auth = token ? token.accessTokenFromBackend : null | ||
const token = await getToken({ req }); | ||
const auth = token ? token.accessTokenFromBackend : null; | ||
let userId = await getTokenDetails(auth); | ||
|
||
console.log(userId); | ||
const user = await Users.findById(userId); | ||
|
||
if (user.event1TeamRole != "1") { | ||
if (user.event1TeamRole != 1) { | ||
return NextResponse.json({ | ||
message: "Leader cant leave the team", | ||
message: 'Leader cant leave the team', | ||
}); | ||
} | ||
|
||
if (!user.event1TeamId) { | ||
return NextResponse.json({ | ||
message: "User is not part of any team", | ||
message: 'User is not part of any team', | ||
}); | ||
} | ||
|
||
const team = await TeamModel.findById(user.event1TeamId); | ||
const team = await Event1.findById(user.event1TeamId); | ||
if (!team) { | ||
return NextResponse.json({ | ||
message: "Team not found", | ||
message: 'Team not found', | ||
}); | ||
} | ||
|
||
team.members.pull(userId); | ||
await team.save(); | ||
|
||
await Users.findByIdAndUpdate(userId, { $set: { teamId: null, teamRole:-1 } }); | ||
|
||
|
||
|
||
|
||
return NextResponse.json({ message: "User has left the team successfully ", status: 200, teamDetails: team }); | ||
|
||
|
||
|
||
|
||
}catch(error) { | ||
console.error("An error occurred:", error); | ||
return NextResponse.json({ message: "Error occurred ", status: 500 }); | ||
await Users.findByIdAndUpdate(userId, { | ||
$set: { event1TeamId: null, event1TeamRole: -1 }, | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: 'User has left the team successfully ', | ||
status: 200, | ||
teamDetails: team, | ||
}); | ||
} catch (error) { | ||
console.error('An error occurred:', error); | ||
return NextResponse.json({ | ||
message: 'Error occurred ', | ||
status: 500, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { connectMongoDB } from "@/lib/mongodb"; | ||
import { Users } from "@/models/user.js"; | ||
import { getTokenDetails } from "@/utils/authuser.js"; | ||
import { getToken } from "next-auth/jwt"; | ||
import { headers } from 'next/headers'; | ||
import { NextResponse } from "next/server"; | ||
|
||
|
||
export async function POST(req){ | ||
try{ | ||
await connectMongoDB(); | ||
const headersList = headers() | ||
// const authorization = headersList.get('authorization') | ||
const token = await getToken({req}) | ||
//console.log('ff', token) | ||
console.log(token.accessTokenFromBackend); | ||
// const auth = req.headers.get("authorization").split(' ')[1]; | ||
|
||
let userId = await getTokenDetails(token.accessTokenFromBackend); | ||
console.log(userId); | ||
const user=await Users.findById(userId); | ||
console.log(user); | ||
|
||
const {regNo,mobno}=await req.json(); | ||
|
||
await Users.findByIdAndUpdate(userId,{$set:{regNo:regNo,mobno:mobno}}) | ||
// console.log(newUserDetail); | ||
// const { accessToken, refreshToken } = await generateTokens(newUserDetail); | ||
// console.log(accessToken); | ||
// console.log(refreshToken); | ||
|
||
//console.log(accessToken); | ||
|
||
return NextResponse.json({ message: "User Details entered ", status: 200 }); | ||
|
||
|
||
}catch(error) { | ||
console.error("An error occurred:", error); | ||
return NextResponse.json({ message: "Error occurred ", status: 500 }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.