diff --git a/scripts/dropEmailIndex.js b/scripts/dropEmailIndex.js new file mode 100644 index 0000000..e716e25 --- /dev/null +++ b/scripts/dropEmailIndex.js @@ -0,0 +1,38 @@ +const mongoose = require("mongoose"); + +const MONGODB_URI = process.env.MONGODB_URI || "mongodb://localhost:27017/test"; + +async function dropEmailIndex() { + try { + await mongoose.connect(MONGODB_URI); + console.log("Connected to MongoDB"); + + const db = mongoose.connection.db; + const collection = db.collection("icebreaker25"); + + const indexes = await collection.indexes(); + console.log("Current indexes:", indexes); + + try { + await collection.dropIndex("email_1"); + console.log("Successfully dropped email_1 index"); + } catch (error) { + if (error.code === 27) { + console.log("email_1 index does not exist"); + } else { + throw error; + } + } + + const newIndexes = await collection.indexes(); + console.log("Remaining indexes:", newIndexes); + + await mongoose.connection.close(); + console.log("Done!"); + } catch (error) { + console.error("Error:", error); + process.exit(1); + } +} + +dropEmailIndex(); diff --git a/src/app/api/icebreaker-register/route.js b/src/app/api/icebreaker-register/route.js index 5c7b146..ae78d5c 100644 --- a/src/app/api/icebreaker-register/route.js +++ b/src/app/api/icebreaker-register/route.js @@ -1,6 +1,6 @@ -import { NextResponse } from 'next/server'; import { connect } from "@/src/dbconfig/dbconfig"; import Icebreaker from "@/src/models/icebreakerModel"; +import { NextResponse } from "next/server"; export async function POST(request) { try { @@ -9,9 +9,9 @@ export async function POST(request) { if (!name || !usn) { return NextResponse.json( - { - success: false, - message: 'Name and USN are required' + { + success: false, + message: "Name and USN are required", }, { status: 400 } ); @@ -20,14 +20,14 @@ export async function POST(request) { await connect(); const existingUser = await Icebreaker.findOne({ - usn: usn.toUpperCase() + usn: usn.toUpperCase(), }); if (existingUser) { return NextResponse.json( - { - success: false, - message: 'This USN is already registered' + { + success: false, + message: "This USN is already registered", }, { status: 409 } ); @@ -36,50 +36,38 @@ export async function POST(request) { const newRegistration = await Icebreaker.create({ name: name.trim(), usn: usn.trim().toUpperCase(), - questionForClub: questionForClub ? questionForClub.trim() : "" + questionForClub: questionForClub ? questionForClub.trim() : "", }); return NextResponse.json( { success: true, - message: 'Registration successful! Get ready for the game!', + message: "Registration successful!", data: { id: newRegistration._id, name: newRegistration.name, - usn: newRegistration.usn - } + usn: newRegistration.usn, + }, }, { status: 201 } ); - } catch (error) { - console.error('Registration error:', error); - - if (error.name === 'ValidationError') { - const errors = Object.values(error.errors).map(err => err.message); - return NextResponse.json( - { - success: false, - message: errors.join(', ') - }, - { status: 400 } - ); - } + console.error("Registration error:", error); if (error.code === 11000) { return NextResponse.json( - { - success: false, - message: 'This USN is already registered' + { + success: false, + message: "This USN is already registered", }, { status: 409 } ); } return NextResponse.json( - { - success: false, - message: 'Something went wrong. Please try again.' + { + success: false, + message: "Registration failed. Please try again.", }, { status: 500 } ); diff --git a/src/components/IcebreakerForm/IcebreakerForm.jsx b/src/components/IcebreakerForm/IcebreakerForm.jsx index 332d7d5..b8e3df4 100644 --- a/src/components/IcebreakerForm/IcebreakerForm.jsx +++ b/src/components/IcebreakerForm/IcebreakerForm.jsx @@ -5,15 +5,15 @@ import styles from "./IcebreakerForm.module.css"; import { useIcebreakerForm } from "./useIcebreakerForm"; export default function IcebreakerForm() { - const { - formData, - errors, - isSubmitting, - submitStatus, - handleChange, - handleSubmit + const { + formData, + errors, + isSubmitting, + submitStatus, + handleChange, + handleSubmit } = useIcebreakerForm(); - + const [registrationComplete, setRegistrationComplete] = useState(false); useEffect(() => { @@ -27,14 +27,14 @@ export default function IcebreakerForm() {
- Join our WhatsApp group for all the further updates and alongside tech talk, project colabs and meet likeminded peers. + Join our WhatsApp group for all the further updates and alongside tech talk, project colabs and meet likeminded peers.
- @@ -60,7 +60,6 @@ export default function IcebreakerForm() { onChange={handleChange} placeholder="Enter your full name" className={styles.input} - maxLength={100} required />