diff --git a/src/model/events.js b/src/model/events.js new file mode 100644 index 0000000..5b371a2 --- /dev/null +++ b/src/model/events.js @@ -0,0 +1,38 @@ + +const mongoose = require("mongoose"); + +const EventSchema = new mongoose.Schema( + { + title: { + type: String, + trim: true, + }, + eventDate : { + type : Date, + required : false + }, + proposedStartDate: { + type: Date, + required: true, + }, + proposedEndDate: { + type: Date, + required:true + }, + hostProposedEndDate: { + type: Date, + required:true + }, + hostProposedEndDate: { + type: Date, + required:true + }, + }, + { + timestamps: true + } +); + + +// Export the model +module.exports = mongoose.model("Event", EventSchema); \ No newline at end of file diff --git a/src/model/participate.js b/src/model/participate.js new file mode 100644 index 0000000..be87e0f --- /dev/null +++ b/src/model/participate.js @@ -0,0 +1,33 @@ + +const mongoose = require("mongoose"); + +const ParticipateSchema = new mongoose.Schema( + { + + event_id: { + type: mongoose.Types, + ref: 'Event', + required: true + }, + eventType: { + type: String, + trim: true, + }, + proposedStartDate: { + type: Date, + required: true, + }, + proposedEndDate: { + type: Date, + required: true + }, + + }, + { + timestamps: true + } +); + + +// Export the model +module.exports = mongoose.model("Participate", ParticipateSchema); \ No newline at end of file diff --git a/src/model/user.js b/src/model/user.js new file mode 100644 index 0000000..fba6c17 --- /dev/null +++ b/src/model/user.js @@ -0,0 +1,44 @@ +const bcrypt = require("bcrypt"); +const { BCRYPT_SALT } = process.env; +const mongoose = require("mongoose"); + +const UserSchema = new mongoose.Schema( + { + goggleId: { + type: String, + trim: true, + required: false, + }, + signup_type : { + type : String, + trim : true, + enum : ["email", "third-party"], + default : "email", + required : true + }, + email: { + type: String, + trim: true, + unique: true, + required: [true, "Email is required"], + }, + password: { + type: String, + }, + }, + { + timestamps: true + } +); + +UserSchema.pre("save", async function (next) { + if (!this.isModified('password')) return next() + + const hash = await bcrypt.hash(this.password, parseInt(BCRYPT_SALT)); + this.password = hash; + + next(); +}); + +// Export the model +module.exports = mongoose.model("User", UserSchema);