-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
307 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const MONGODB_URI = process.env.MONGODB_URI; | ||
|
||
let cached = (global as any).mongoose || { conn: null, promise: null }; | ||
|
||
export const connectToDatabase = async () => { | ||
if (cached.conn) return cached.conn; | ||
|
||
if (!MONGODB_URI) throw new Error("MONGODB_URI is missing!"); | ||
|
||
cached.promise = | ||
cached.promise || | ||
mongoose.connect(MONGODB_URI, { | ||
dbName: "evently-nextjs", | ||
bufferCommands: false, | ||
}); | ||
|
||
cached.conn = await cached.promise; | ||
|
||
return cached.conn; | ||
}; |
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,36 @@ | ||
import { Document, Schema, model, models } from "mongoose"; | ||
|
||
export interface IEvent extends Document { | ||
_id: string; | ||
title: string; | ||
description?: string; | ||
location?: string; | ||
createdAt: string; | ||
imageUrl: string; | ||
startDateTime: string; | ||
endDateTime: string; | ||
price: string; | ||
isFree: boolean; | ||
url?: string; | ||
category: { _id: string; name: string }; | ||
organizer: { _id: string; firstName: string; lastName: string }; | ||
} | ||
|
||
const EventSchema = new Schema({ | ||
title: { type: String, required: true }, | ||
description: { type: String }, | ||
location: { type: String }, | ||
createdAt: { type: Date, default: Date.now }, | ||
imageUrl: { type: String, required: true }, | ||
startDateTime: { type: Date, default: Date.now }, | ||
endDateTime: { type: Date, default: Date.now }, | ||
price: { type: String }, | ||
isFree: { type: Boolean, default: false }, | ||
url: { type: String }, | ||
category: { type: Schema.Types.ObjectId, ref: "Category" }, | ||
organizer: { type: Schema.Types.ObjectId, ref: "User" }, | ||
}); | ||
|
||
const Event = models.Event || model("Event", EventSchema); | ||
|
||
export default Event; |
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,14 @@ | ||
import { Schema, model, models } from "mongoose"; | ||
|
||
const UserSchema = new Schema({ | ||
clerkId: { type: String, required: true, unique: true }, | ||
email: { type: String, required: true, unique: true }, | ||
username: { type: String, required: true, unique: true }, | ||
firstName: { type: String, required: true }, | ||
lastName: { type: String, required: true }, | ||
photo: { type: String, required: true }, | ||
}); | ||
|
||
const User = models.User || model("User", UserSchema); | ||
|
||
export default User; |
Oops, something went wrong.