diff --git a/app/api/create-tournament/route.js b/app/api/create-tournament/route.js
index 504ed7c..7fec0c7 100644
--- a/app/api/create-tournament/route.js
+++ b/app/api/create-tournament/route.js
@@ -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 }
+ );
}
-}
+}
\ No newline at end of file
diff --git a/app/api/games/route.js b/app/api/games/route.js
index baab93d..aa4cce9 100644
--- a/app/api/games/route.js
+++ b/app/api/games/route.js
@@ -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 });
}
}
diff --git a/app/api/tournaments/[id]/route.js b/app/api/tournaments/[id]/route.js
index 480b810..555abee 100644
--- a/app/api/tournaments/[id]/route.js
+++ b/app/api/tournaments/[id]/route.js
@@ -1,18 +1,23 @@
import { NextResponse } from 'next/server';
-import { PrismaClient } from '@prisma/client';
-
-const prisma = new PrismaClient();
+import dbConnect from "../../../../lib/dbConnect";
+import Tournament from '../../../../model/Tournament';
+import Games from '../../../../model/Games';
+import Organizer from '../../../../model/Organizer';
export async function GET(request, { params }) {
+ await dbConnect();
+
try {
const id = params.id;
- const tournament = await prisma.tournament.findUnique({
- where: { id },
- include: {
- game: true,
- organizer: true,
- },
- });
+
+ // Ensure all models are registered
+ Games;
+ Organizer;
+
+ const tournament = await Tournament.findById(id)
+ .populate('gameId')
+ .populate('organizerId')
+ .lean();
if (tournament) {
return NextResponse.json(tournament);
@@ -21,6 +26,6 @@ export async function GET(request, { params }) {
}
} catch (error) {
console.error('Error fetching tournament:', error);
- return NextResponse.json({ error: 'Error fetching tournament' }, { status: 500 });
+ return NextResponse.json({ error: 'Error fetching tournament', details: error.message }, { status: 500 });
}
}
\ No newline at end of file
diff --git a/app/api/tournaments/route.js b/app/api/tournaments/route.js
index c85a2c9..b674e26 100644
--- a/app/api/tournaments/route.js
+++ b/app/api/tournaments/route.js
@@ -1,9 +1,12 @@
import { NextResponse } from 'next/server';
-import { PrismaClient } from '@prisma/client';
-
-const prisma = new PrismaClient();
+import dbConnect from "../../../lib/dbConnect";
+import Tournament from '../../../model/Tournament';
+import Games from '../../../model/Games';
+import Organizer from '../../../model/Organizer';
export async function GET(request) {
+ await dbConnect();
+
const { searchParams } = new URL(request.url);
const page = parseInt(searchParams.get('page') || '1');
const limit = parseInt(searchParams.get('limit') || '10');
@@ -12,24 +15,25 @@ export async function GET(request) {
const skip = (page - 1) * limit;
- const where = {};
- if (gameType) where.gameType = gameType;
- if (organizerId) where.organizerId = organizerId;
+ const query = {};
+ if (gameType) query.gameType = gameType;
+ if (organizerId) query.organizerId = organizerId;
try {
console.log('Fetching tournaments with params:', { page, limit, gameType, organizerId });
- const tournaments = await prisma.tournament.findMany({
- where,
- include: {
- game: true,
- organizer: true,
- },
- skip,
- take: limit,
- });
+ // Ensure models are registered
+ Games;
+ Organizer;
+
+ const tournaments = await Tournament.find(query)
+ .populate('gameId', 'name category gameBannerPhoto')
+ .populate('organizerId', 'orgName bannerPhoto')
+ .skip(skip)
+ .limit(limit)
+ .lean();
- const total = await prisma.tournament.count({ where });
+ const total = await Tournament.countDocuments(query);
console.log(`Found ${tournaments.length} tournaments out of ${total} total`);
diff --git a/app/tournaments/[id]/page.js b/app/tournaments/[id]/page.js
index f45a703..6606df0 100644
--- a/app/tournaments/[id]/page.js
+++ b/app/tournaments/[id]/page.js
@@ -2,20 +2,32 @@ import Image from 'next/image';
import Link from 'next/link';
import { CalendarIcon, ClockIcon, PersonIcon, CrossCircledIcon, LockClosedIcon } from '@radix-ui/react-icons';
import { Trophy, DollarSign, Users, Shield } from 'lucide-react';
-import prisma from '../../../lib/db';
+import dbConnect from '../../../lib/dbConnect';
+import Tournament from '../../../model/Tournament';
async function getTournament(id) {
- const tournament = await prisma.tournament.findUnique({
- where: { id },
- include: {
- game: true,
- organizer: true,
- },
- });
- return tournament;
+ await dbConnect();
+ if (!id) {
+ console.error('Tournament ID is undefined');
+ return null;
+ }
+ try {
+ const tournament = await Tournament.findById(id)
+ .populate('gameId')
+ .populate('organizerId')
+ .lean();
+ return tournament ? JSON.parse(JSON.stringify(tournament)) : null;
+ } catch (error) {
+ console.error('Error fetching tournament:', error);
+ return null;
+ }
}
export default async function TournamentPage({ params }) {
+ if (!params || !params.id) {
+ return
Invalid tournament ID
;
+ }
+
const tournament = await getTournament(params.id);
if (!tournament) {
@@ -27,7 +39,7 @@ export default async function TournamentPage({ params }) {
Host
- {tournament.organizer.orgName}
+ {tournament.organizerId?.orgName || "Unknown Organizer"}
Description
-
{tournament.game.profile}
+
{tournament.gameId?.profile || "No description available"}
@@ -120,7 +132,7 @@ export default async function TournamentPage({ params }) {
-
+
Register for Tournament
diff --git a/components/TournamentSection.jsx b/components/TournamentSection.jsx
index 8cfee9c..85f1fa8 100644
--- a/components/TournamentSection.jsx
+++ b/components/TournamentSection.jsx
@@ -73,8 +73,8 @@ export default function TournamentSection({ filters }) {
{filteredTournaments.map((tournament) => (
@@ -93,8 +93,8 @@ function TournamentCard({
prize,
slots,
registeredNumber,
- game,
- organizer,
+ gameId,
+ organizerId,
}) {
const getStatus = () => {
const now = new Date();
@@ -132,7 +132,9 @@ function TournamentCard({
{status}
- {organizer.orgName}
+ {organizerId ? organizerId.orgName : "Unknown Organizer"}
Host
diff --git a/model/Games.js b/model/Games.js
new file mode 100644
index 0000000..61131d9
--- /dev/null
+++ b/model/Games.js
@@ -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;
\ No newline at end of file
diff --git a/model/Organizer.js b/model/Organizer.js
new file mode 100644
index 0000000..ea3963c
--- /dev/null
+++ b/model/Organizer.js
@@ -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;
\ No newline at end of file
diff --git a/model/Tournament.js b/model/Tournament.js
new file mode 100644
index 0000000..afb7055
--- /dev/null
+++ b/model/Tournament.js
@@ -0,0 +1,35 @@
+const mongoose = require('mongoose');
+const Schema = mongoose.Schema;
+
+const TournamentSchema = new Schema({
+ tournamentName: String,
+ tournamentDates: {
+ created: { type: Date, default: Date.now },
+ started: Date,
+ ended: Date
+ },
+ schedules: Schema.Types.Mixed,
+ organizerId: { type: Schema.Types.ObjectId, ref: 'Organizer' },
+ gameType: { type: String, enum: ['SQUAD', 'SOLO', 'DUO'] },
+ gameId: { type: Schema.Types.ObjectId, ref: 'Games' },
+ links: Schema.Types.Mixed,
+ gameBannerPhoto: String,
+ results: [Schema.Types.Mixed],
+ teamsRegistered: [{
+ id: Schema.Types.ObjectId,
+ name: String,
+ members: [Schema.Types.ObjectId]
+ }],
+ rounds: [Schema.Types.Mixed],
+ teamSize: Number,
+ prize: [Schema.Types.Mixed],
+ howToX: [String],
+ rules: String,
+ slots: Number,
+ email: String,
+ registeredNumber: { type: Number, default: 0 }
+});
+
+const Tournament = mongoose.models.Tournament || mongoose.model('Tournament', TournamentSchema);
+
+module.exports = Tournament;
\ No newline at end of file
diff --git a/model/User.js b/model/User.js
index be06474..2088976 100644
--- a/model/User.js
+++ b/model/User.js
@@ -41,17 +41,17 @@ const userSchema = new Schema({
type: Date,
default: Date.now,
},
- verifyCode:{
+ verifyCode: {
type: String,
required: [true, "Verification Code is required"]
},
- verifyCodeExpiry:{
- type: Date,
- required: [true, "Verify code expiry is a must"]
+ verifyCodeExpiry: {
+ type: Date,
+ required: [true, "Verify code expiry is a must"]
},
- password:{
- type: String || '',
- required: [true, "Password is required"]
+ password: {
+ type: String || '',
+ required: [true, "Password is required"]
},
eventsRegistered: [
{
diff --git a/prisma/seed.js b/prisma/seed.js
index 7117c86..f479908 100644
--- a/prisma/seed.js
+++ b/prisma/seed.js
@@ -1,11 +1,12 @@
-const { PrismaClient, GameType } = require('@prisma/client');
const mongoose = require('mongoose');
const bcrypt = require('bcrypt');
+require('dotenv').config();
-const prisma = new PrismaClient();
-
-// Import the Mongoose User model
+// Import the Mongoose models
+const GamesModel = require('../model/Games');
const UserModel = require('../model/User');
+const OrganizerModel = require('../model/Organizer');
+const TournamentModel = require('../model/Tournament');
const { TeamModel } = require('../model/Team');
async function connectToMongoDB() {
@@ -32,19 +33,17 @@ async function main() {
];
for (const game of gameData) {
- const existingGame = await prisma.games.findUnique({
- where: { name: game.name },
- });
+ const existingGame = await GamesModel.findOne({ name: game.name });
if (!existingGame) {
- await prisma.games.create({ data: game });
+ await GamesModel.create(game);
console.log(`Game ${game.name} inserted successfully`);
} else {
console.log(`Game ${game.name} already exists`);
}
}
- // Seed Users (Mongoose)
+ // Seed Users
const userData = [
{
username: 'player1',
@@ -77,7 +76,7 @@ async function main() {
}
}
- // Seed Organizers (prisma)
+ // Seed Organizers
const organizerData = [
{
orgName: 'Epic Gaming',
@@ -94,19 +93,17 @@ async function main() {
];
for (const organizer of organizerData) {
- const existingOrganizer = await prisma.organizer.findUnique({
- where: { orgEmail: organizer.orgEmail },
- });
+ const existingOrganizer = await OrganizerModel.findOne({ orgEmail: organizer.orgEmail });
if (!existingOrganizer) {
- await prisma.organizer.create({ data: organizer });
+ await OrganizerModel.create(organizer);
console.log(`Organizer ${organizer.orgName} inserted successfully`);
} else {
console.log(`Organizer ${organizer.orgName} already exists`);
}
}
- // Seed Tournaments (prisma)
+ // Seed Tournaments
const tournamentData = [
{
tournamentName: 'BGMI Pro League',
@@ -114,7 +111,7 @@ async function main() {
started: new Date('2024-08-01'),
ended: new Date('2024-08-15'),
},
- gameType: GameType.SQUAD,
+ gameType: 'SQUAD',
teamSize: 4,
slots: 16,
prize: [{ rank: 1, amount: 10000 }, { rank: 2, amount: 5000 }, { rank: 3, amount: 2500 }],
@@ -127,7 +124,7 @@ async function main() {
started: new Date('2024-09-01'),
ended: new Date('2024-09-10'),
},
- gameType: GameType.SOLO,
+ gameType: 'SOLO',
teamSize: 1,
slots: 32,
prize: [{ rank: 1, amount: 5000 }, { rank: 2, amount: 2500 }, { rank: 3, amount: 1000 }],
@@ -137,25 +134,21 @@ async function main() {
];
for (const tournament of tournamentData) {
- const existingTournament = await prisma.tournament.findFirst({
- where: { tournamentName: tournament.tournamentName },
- });
+ const existingTournament = await TournamentModel.findOne({ tournamentName: tournament.tournamentName });
if (!existingTournament) {
- const game = await prisma.games.findFirst({
- where: { name: tournament.tournamentName.includes('BGMI') ? 'BGMI' : 'Call of Duty Mobile' },
+ const game = await GamesModel.findOne({
+ name: tournament.tournamentName.includes('BGMI') ? 'BGMI' : 'Call of Duty Mobile'
});
- const organizer = await prisma.organizer.findFirst({
- where: { orgName: tournament.email.includes('protournaments') ? 'Pro Tournaments' : 'Epic Gaming' },
+ const organizer = await OrganizerModel.findOne({
+ orgName: tournament.email.includes('protournaments') ? 'Pro Tournaments' : 'Epic Gaming'
});
if (game && organizer) {
- await prisma.tournament.create({
- data: {
- ...tournament,
- gameId: game.id,
- organizerId: organizer.id,
- },
+ await TournamentModel.create({
+ ...tournament,
+ gameId: game._id,
+ organizerId: organizer._id,
});
console.log(`Tournament ${tournament.tournamentName} inserted successfully`);
} else {
@@ -166,8 +159,7 @@ async function main() {
}
}
-
- // seed Team (mongoose)
+ // Seed Teams
const teamData = [
{
image: 'https://example.com/image1.jpg',
@@ -203,8 +195,6 @@ async function main() {
console.log(`Team ${team.teamname} already exists`);
}
}
-
-
}
main()
@@ -213,6 +203,5 @@ main()
process.exit(1);
})
.finally(async () => {
- await prisma.$disconnect();
await mongoose.disconnect();
});
\ No newline at end of file