From 914257a010eeda96683df33bef789a838334b411 Mon Sep 17 00:00:00 2001 From: Denish Bhuva Date: Wed, 18 Dec 2024 18:30:21 +0530 Subject: [PATCH 1/2] Update .env.example --- .env.example | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.env.example b/.env.example index cb97a23..80e5254 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,15 @@ -DATABASE_URL="" -MONGODB_URL='' +DATABASE_URL='' RESEND_API_KEY='' NEXTAUTH_SECRET='' NEXTAUTH_URL='' NEWS_URL='' +GOOGLE_CLIENT_ID= +GOOGLE_CLIENT_SECRET= + +DISCORD_CLIENT_ID= +DISCORD_CLIENT_SECRET= + +# For those who working on /blogs page SANITY_STUDIO_PROJECT_ID='' SANITY_STUDIO_DATASET='' \ No newline at end of file From d7e125a1bb4d028727b981b826f6b1cec1d18681 Mon Sep 17 00:00:00 2001 From: Denish Bhuva Date: Wed, 18 Dec 2024 18:46:52 +0530 Subject: [PATCH 2/2] Improve team registration in Tournament --- .../tournaments/[id]/registration/route.js | 52 +++++++++++++++---- model/Tournament.js | 38 +++++++++----- prisma/schema.prisma | 8 +-- 3 files changed, 71 insertions(+), 27 deletions(-) diff --git a/app/api/tournaments/[id]/registration/route.js b/app/api/tournaments/[id]/registration/route.js index 74962a6..c06a48e 100644 --- a/app/api/tournaments/[id]/registration/route.js +++ b/app/api/tournaments/[id]/registration/route.js @@ -1,34 +1,64 @@ import { NextResponse } from "next/server"; import dbConnect from "../../../../../lib/dbConnect"; import Tournament from "../../../../../model/Tournament"; +import mongoose from "mongoose"; async function handler(request, { params }) { await dbConnect(); const id = params.id; - const { registrationData } = await request.json(); try { + const { name, members, email, selectedPlatform, participantType } = + await request.json(); + + if (!name || !members || !email || !selectedPlatform || !participantType) { + return NextResponse.json( + { message: "All fields are required for registration" }, + { status: 400 } + ); + } + + if (!Array.isArray(members) || members.some((member) => typeof member !== "string")) { + return NextResponse.json( + { message: "Invalid members format. Members must be an array of strings." }, + { status: 400 } + ); + } + + const teamRegistration = { + id: new mongoose.Types.ObjectId(), + name, + members, + email, + selectedPlatform, + participantType, + }; + const updatedTournament = await Tournament.findByIdAndUpdate( id, - { registrations: registrationData }, + { $push: { teamsRegistered: teamRegistration } }, { new: true } ); if (!updatedTournament) { - return NextResponse.status(404).json({ message: "Tournament not found" }); + return NextResponse.json( + { message: "Tournament not found" }, + { status: 404 } + ); } - return NextResponse.status(200).json({ - message: "Registration updated successfully", - tournament: updatedTournament, + return NextResponse.json({ + message: "Registration successful", + teamRegistration, }); } catch (error) { - console.error("Error while updating tournament", error); - return NextResponse.status(500).json({ - message: "Error while updating the registration", - }); + console.error("Error while registering for the tournament:", error); + return NextResponse.json( + { message: "An error occurred during registration" }, + { status: 500 } + ); } } -export { handler as POST }; +export { handler as POST }; \ No newline at end of file diff --git a/model/Tournament.js b/model/Tournament.js index 1207294..6750261 100644 --- a/model/Tournament.js +++ b/model/Tournament.js @@ -1,12 +1,13 @@ const mongoose = require('mongoose'); const Schema = mongoose.Schema; -const TournamentSchema = new Schema({ +const TournamentSchema = new Schema( + { tournamentName: { type: String, required: true }, tournamentDates: { - created: { type: Date, default: Date.now }, - started: Date, - ended: Date + created: { type: Date, default: Date.now }, + started: Date, + ended: Date, }, schedules: Schema.Types.Mixed, organizerId: { type: Schema.Types.ObjectId, ref: 'Organizer', required: true }, @@ -15,15 +16,20 @@ const TournamentSchema = new Schema({ links: Schema.Types.Mixed, gameBannerPhoto: String, results: [Schema.Types.Mixed], - teamsRegistered: [{ - id: Schema.Types.ObjectId, + teamsRegistered: [ + { + id: { type: mongoose.Schema.Types.ObjectId, required: true }, name: { type: String, required: true }, - members: [{ type: Schema.Types.ObjectId, ref: 'User' }] - }], + members: [{ type: String }], + email: { type: String, required: true, lowercase: true, trim: true }, + selectedPlatform: { type: String, required: true }, + participantType: { type: String, required: true }, + }, + ], participantCount: { - type: Number, - required: true, - min: 1 + type: Number, + required: true, + min: 1, }, rounds: [Schema.Types.Mixed], teamSize: { type: Number, min: 1 }, @@ -41,7 +47,11 @@ const TournamentSchema = new Schema({ minTeamMembers: { type: Number, min: 1 }, maxTeams: { type: Number, min: 1 }, minTeams: { type: Number, min: 1 }, - tournamentVisibility: { type: String, enum: ['public', 'private'], default: 'public' }, + tournamentVisibility: { + type: String, + enum: ['public', 'private'], + default: 'public', + }, inviteCode: String, prizeConfig: [Schema.Types.Mixed], sponsors: [Schema.Types.Mixed], @@ -60,7 +70,9 @@ const TournamentSchema = new Schema({ selectedTimezone: String, size: String, brackets: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Bracket' }], -}, { timestamps: true }); + }, + { timestamps: true } +); // Indexes remain the same diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 404aff1..0f56e13 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -68,12 +68,14 @@ type TournamentDates { type TeamRegistration { id String @db.ObjectId name String - members String[] @db.ObjectId + members String[] + email String + selectedPlatform String + participantType String } enum GameType { SQUAD SOLO DUO -} - +} \ No newline at end of file