MODELS
USER MODEL
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const Model = mongoose.model;
const bcrypt = require("bcryptjs");
const userSchema = new Schema({
name: {
type: String,
required: true,
},
username: {
type: String,
required: true,
unique: true,
},
email: {
type: String,
required: true,
unique: true,
},
password: {
type: String,
required: true,
},
});
userSchema.pre("save", async function (next) {
if (this.isModified("password")) {
this.password = await bcrypt.hash(this.password, 10);
}
next();
});
const User = new Model("User", userSchema);
module.exports = User;
MEETING MODEL
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const Model = mongoose.model;
const MeetingSchema = new Schema({
user_id: {
type: String,
required: true,
},
meeting_code: {
type: String,
required: true,
},
participants: [
{
username: { type: String },
role: { type: String, enum: ["host", "participant"] },
},
],
date: {
type: Date,
required: true,
default: Date.now(),
},
status: {
type: String,
required: true,
enum: ["live", "ended"],
default: "live",
},
});
const Meeting = new Model("Meeting", MeetingSchema);
module.exports = Meeting;
Comments
Post a Comment