-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from vaibhavgarg25/main
feat : transfer database from firebase to mongodb
- Loading branch information
Showing
10 changed files
with
1,231 additions
and
377 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
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,26 @@ | ||
import mongoose from 'mongoose'; | ||
|
||
const MONGODB_URI = process.env.NEXT_PUBLIC_MONGODB_URI; | ||
|
||
type ConnectionObject={ | ||
isConnected?:number | ||
} | ||
|
||
const connection:ConnectionObject={} | ||
|
||
async function connectMongoDB():Promise<void> { | ||
if(connection.isConnected){ | ||
console.log("already connected to database") | ||
return | ||
} | ||
try { | ||
const db=await mongoose.connect(MONGODB_URI || '') | ||
connection.isConnected=db.connections[0].readyState | ||
console.log("db connected successfully") | ||
} catch (error) { | ||
console.log("database connection failed",error) | ||
process.exit(0) | ||
} | ||
} | ||
|
||
export default connectMongoDB; |
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,56 @@ | ||
import mongoose, { Document, Schema } from "mongoose"; | ||
|
||
// Define the Member interface | ||
export interface Achievement extends Document { | ||
name: string; | ||
batch: string | null; | ||
email: string | null; | ||
portfolio: string | null; | ||
internship: string | null; | ||
companyPosition: string | null; | ||
achievements: string[]; | ||
imageUrl: string | null; | ||
} | ||
|
||
// Create the schema for the Member model | ||
const AchievementSchema: Schema<Achievement> = new Schema( | ||
{ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
batch: { | ||
type: String, | ||
required: true | ||
}, | ||
portfolio: { | ||
type: String, | ||
required: true | ||
}, | ||
internship: { | ||
type:String, | ||
required: true, | ||
}, | ||
companyPosition: { | ||
type: String, | ||
required: true, | ||
}, | ||
achievements: { | ||
type: [String], // Array of strings | ||
required: true, | ||
}, | ||
imageUrl: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
); | ||
|
||
// Create a model from the schema | ||
const AchievementModel = mongoose.models.achievements || mongoose.model<Achievement>("achievements", AchievementSchema); | ||
|
||
export default AchievementModel; |
Oops, something went wrong.