Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pages/api/v1/recruitment/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DBInstance from "@/utils/db";
import RecruitmentDBInstance from "@/utils/db";
import Participant from "@/utils/models/recruitment.model.js";

DBInstance();
RecruitmentDBInstance();

export default async function handler(req, res) {
if (req.method === "POST") {
Expand Down
18 changes: 17 additions & 1 deletion utils/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import dotenv from "dotenv";

dotenv.config();

const { MONGO_URI, DB_NAME } = process.env;
const { MONGO_URI, DB_NAME , RECRUITMENT_MONGO_URI , RECRUITMENT_DB_NAME } = process.env;

const DBInstance = async () => {
try {
Expand All @@ -20,4 +20,20 @@ const DBInstance = async () => {
}
};

const RecruitmentDBInstance = async () => {
try {
await mongoose.connect(RECRUITMENT_MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: RECRUITMENT_DB_NAME
});

// console.log(`✅ Connected to MongoDB: ${NEXT_PUBLIC_DB_NAME}`);
} catch (err) {
// console.error("❌ Could not connect to MongoDB\n", err.message);
throw err;
}
};

export default DBInstance;
export {RecruitmentDBInstance}
2 changes: 1 addition & 1 deletion utils/models/recruitment.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ const participantSchema = new mongoose.Schema({
}
});

const ParticipantUser = mongoose.models.Recruitment24 || mongoose.model("Recruitment24", participantSchema);
const ParticipantUser = mongoose.models.Recruitment25 || mongoose.model("Recruitment25", participantSchema);
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model name 'Recruitment25' contains a typo. It should be 'Recruitment25' instead of 'recrutiment25' to match the PR title, or the PR title should be corrected to match the code.

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the model name from 'Recruitment24' to 'Recruitment25' will create a new collection in the database. This is a breaking change that could result in data loss if existing 'Recruitment24' data needs to be migrated. Consider implementing a data migration strategy or ensuring this change is intentional.

Suggested change
const ParticipantUser = mongoose.models.Recruitment25 || mongoose.model("Recruitment25", participantSchema);
const ParticipantUser = mongoose.models.Recruitment24 || mongoose.model("Recruitment24", participantSchema);

Copilot uses AI. Check for mistakes.

module.exports = ParticipantUser;