-
-
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
11 changed files
with
211 additions
and
139 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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// model/Games.js | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
const GamesSchema = new Schema({ | ||
name: { type: String, unique: true }, | ||
category: String, | ||
profile: String, | ||
gameBannerPhoto: String | ||
}); | ||
|
||
const Games = mongoose.models.Games || mongoose.model('Games', GamesSchema); | ||
|
||
module.exports = Games; |
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,19 @@ | ||
const mongoose = require('mongoose'); | ||
const Schema = mongoose.Schema; | ||
|
||
const OrganizerSchema = new Schema({ | ||
orgName: { type: String, unique: true }, | ||
orgEmail: { type: String, unique: true }, | ||
description: String, | ||
bannerPhoto: String, | ||
twoFactorActivated: { type: Boolean, default: false }, | ||
createdAt: { type: Date, default: Date.now }, | ||
socials: [String], | ||
members: [String] | ||
}); | ||
|
||
// module.exports = mongoose.model('Organizer', OrganizerSchema); | ||
|
||
const Organizer = mongoose.models.Organizer || mongoose.model('Organizer', OrganizerSchema); | ||
|
||
module.exports = Organizer; |
Oops, something went wrong.