-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,161 additions
and
192 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,38 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import { NextResponse } from 'next/server'; | ||
import dbConnect from '../../../lib/dbConnect'; | ||
import Tournament from '../../../model/Tournament'; | ||
|
||
const prisma = new PrismaClient(); | ||
export async function POST(req) { | ||
try { | ||
await dbConnect(); | ||
|
||
export async function POST(req, res) { | ||
{ | ||
const { tournamentName, selectedPlatform, participantType, selectedTimezone, size } = req.body; | ||
const { tournamentName, selectedPlatform, participantType, selectedTimezone, size } = await req.json(); | ||
|
||
try { | ||
await dbConnect(); | ||
const existingTournament = await Tournament.findOne({ tournamentName }); | ||
|
||
const existingTournament = await prisma.tournament.findFirst({ | ||
where: { tournamentName }, | ||
}); | ||
if (existingTournament) { | ||
return NextResponse.json({ message: 'Tournament already exists' }, { status: 409 }); | ||
} | ||
|
||
if (existingTournament) { | ||
return res.status(409).json({ message: 'Tournament already exists' }); | ||
} | ||
const newTournament = new Tournament({ | ||
tournamentName, | ||
platform: selectedPlatform, | ||
participantType, | ||
timezone: selectedTimezone, | ||
size: parseInt(size, 10), | ||
}); | ||
|
||
const newTournament = await prisma.tournament.create({ | ||
data: { | ||
tournamentName, | ||
platform: selectedPlatform, | ||
participantType, | ||
timezone: selectedTimezone, | ||
size: parseInt(size, 10), | ||
}, | ||
}); | ||
await newTournament.save(); | ||
|
||
res.status(200).json({ message: 'Tournament created successfully', tournament: newTournament }); | ||
} catch (error) { | ||
console.error('Error creating tournament:', error); | ||
res.status(500).json({ message: 'An error occurred while creating the tournament' }); | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
return NextResponse.json( | ||
{ message: 'Tournament created successfully', tournament: newTournament }, | ||
{ status: 201 } | ||
); | ||
} catch (error) { | ||
console.error('Error creating tournament:', error); | ||
return NextResponse.json( | ||
{ message: 'An error occurred while creating the tournament' }, | ||
{ 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 |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import { PrismaClient } from '@prisma/client'; | ||
import { NextResponse } from 'next/server'; | ||
import dbConnect from '../../../lib/dbConnect'; | ||
import Games from '../../../model/Games'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export async function GET(req, res) { | ||
export async function GET(req) { | ||
await dbConnect(); | ||
|
||
try { | ||
const gameData = await prisma.games.findMany(); | ||
const existingGames = []; | ||
|
||
for (const game of gameData) { | ||
const existingGame = await prisma.games.findUnique({ | ||
where: { name: game.name }, | ||
}); | ||
existingGames.push(existingGame); | ||
} | ||
const gameData = await Games.find().lean(); | ||
|
||
res.status(200).json(existingGames); | ||
return NextResponse.json(gameData, { status: 200 }); | ||
} catch (error) { | ||
res.status(500).json({ error: 'Internal Server Error' }); | ||
} finally { | ||
await prisma.$disconnect(); | ||
console.error('Error fetching games:', error); | ||
return NextResponse.json({ error: 'Internal Server Error' }, { 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,25 @@ | ||
import { NextResponse } from "next/server"; | ||
import dbConnect from "../../../lib/dbConnect"; | ||
import UserModel from "../../../models/UserModel"; | ||
|
||
export async function POST(request) { | ||
try { | ||
await dbConnect(); | ||
const body = await request.json(); | ||
const { tournamentId, participantName, userId } = body; | ||
|
||
const user = await UserModel.findById(userId); | ||
if (!user) { | ||
return NextResponse.json({ message: "User not found" }, { status: 404 }); | ||
} | ||
|
||
user.eventsRegistered.push(tournamentId); | ||
|
||
await user.save(); | ||
|
||
return NextResponse.json({ message: "Participant added successfully", user }); | ||
} catch (error) { | ||
console.error("Error adding participant:", error); | ||
return NextResponse.json({ message: "An error occurred while adding the participant" }, { 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,30 @@ | ||
import { NextResponse } from "next/server"; | ||
import dbConnect from "../../../../../lib/dbConnect"; | ||
import Tournament from "../../../../../models/Tournament"; | ||
|
||
export default async function POST(request, { params }) { | ||
await dbConnect(); | ||
|
||
const id = params.id; | ||
const { registrationData } = await request.json(); | ||
|
||
try { | ||
const updatedTournament = await Tournament.findByIdAndUpdate( | ||
id, | ||
{ registrations: registrationData }, | ||
{ new: true } | ||
); | ||
|
||
if (!updatedTournament) { | ||
return NextResponse.status(404).json({ message: "Tournament not found" }); | ||
} | ||
|
||
return NextResponse.status(200).json({ | ||
message: "Registration updated successfully", | ||
tournament: updatedTournament | ||
}); | ||
} catch (error) { | ||
console.error("Error while updating tournament", error); | ||
return NextResponse.status(500).json({ message: "Error while updating the registration" }); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { NextResponse } from "next/server"; | ||
import dbConnect from "../../../../../lib/dbConnect"; | ||
import Tournament from "../../../../../models/Tournament"; | ||
|
||
export default async function POST(request, { params }) { | ||
await dbConnect(); | ||
|
||
const id = params.id; // Extract the tournament ID from params | ||
const { structureData } = await request.json(); // Correctly parse the request body | ||
|
||
try { | ||
const updatedTournament = await Tournament.findByIdAndUpdate( | ||
id, | ||
{ structure: structureData }, | ||
{ new: true } | ||
); | ||
|
||
if (!updatedTournament) { | ||
return NextResponse.status(404).json({ message: "Tournament not found" }); | ||
} | ||
|
||
return NextResponse.json({ | ||
message: "Tournament structure updated successfully", | ||
tournament: updatedTournament, | ||
}); | ||
} catch (error) { | ||
console.error("Error updating tournament structure", error); | ||
return NextResponse.json({ | ||
message: "An error occurred while updating the tournament structure", | ||
}, { 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
Oops, something went wrong.