-
-
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
1 parent
5aaa05e
commit 10716a8
Showing
3 changed files
with
47 additions
and
40 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,25 +1,25 @@ | ||
import { NextResponse } from "next/server"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
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 } = body; | ||
|
||
const newParticipant = await prisma.participant.create({ | ||
data: { | ||
name: participantName, | ||
tournamentId, | ||
} | ||
}); | ||
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", participant: newParticipant }); | ||
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 }); | ||
} finally { | ||
await prisma.$disconnect(); | ||
} | ||
} |
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,27 +1,30 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { NextResponse } from "next/server"; | ||
import dbConnect from "../../../../../lib/dbConnect"; | ||
import Tournament from "../../../../../models/Tournament"; | ||
|
||
const prisma = new PrismaClient(); | ||
export default async function POST(request, { params }) { | ||
await dbConnect(); | ||
|
||
export default async function POST(request, {params}){ | ||
|
||
const id = params.id; | ||
const { registrationData } = await request.json(); | ||
|
||
const {registrationData } =request.body | ||
|
||
try { | ||
const updatedTournament = await prisma.tournament.update({ | ||
where: {id}, | ||
data: {registrations: registrationData} | ||
}); | ||
const updatedTournament = await Tournament.findByIdAndUpdate( | ||
id, | ||
{ registrations: registrationData }, | ||
{ new: true } | ||
); | ||
|
||
return NextResponse.status(200).json({message: "Registration updated successfully", tournament: updatedTournament}); | ||
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.log(("error while updating tournament", error)) | ||
return NextResponse.status(500).json({message: "Error while updating the registration"}) | ||
} | ||
finally{ | ||
await prisma.$disconnect(); | ||
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