Skip to content

Commit

Permalink
Updated the model
Browse files Browse the repository at this point in the history
  • Loading branch information
SurajjBhardwaj committed Feb 24, 2024
1 parent 7702cc2 commit 23004c4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
34 changes: 34 additions & 0 deletions models/chatModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import mongoose from "mongoose";

const chatSchema = new mongoose.Schema(
{
participants: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "User", // Reference to the User model
required: true,
},
],
messages: [
{
sender: {
type: mongoose.Schema.Types.ObjectId,
ref: "User", // Reference to the User model
required: true,
},
content: {
type: String,
required: true,
},
timestamp: {
type: Date,
default: Date.now,
},
},
],
},
{ timestamps: true }
);

mongoose.models = {};
export default mongoose.model("Chat", chatSchema);
25 changes: 22 additions & 3 deletions models/userModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const expertiseSchema = new mongoose.Schema({
type: String,
enum: ["Exploring", "Beginner", "Intermediate", "Expert"],
},
topics: [],
topics: [String], // Assuming topics is an array of strings
});

const userSchema = new mongoose.Schema(
Expand All @@ -33,6 +33,7 @@ const userSchema = new mongoose.Schema(
email: {
type: String,
required: true,
unique: true, // Ensure unique email addresses
},
isEmailVerified: {
type: Boolean,
Expand Down Expand Up @@ -60,6 +61,26 @@ const userSchema = new mongoose.Schema(
type: String,
default: "",
},
socketInfo: {
id: {
type: String,
default: "",
},
online: {
type: Boolean,
default: false,
},
},
messages: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Message", // Assuming there's a Message model for chat messages
},
],
connection: {
type: Boolean,
default: false,
},
expertise: [expertiseSchema],
streaks: [streakSchema], // Adding streaks to the user schema
},
Expand All @@ -68,5 +89,3 @@ const userSchema = new mongoose.Schema(

mongoose.models = {};
export default mongoose.model("user", userSchema);


0 comments on commit 23004c4

Please sign in to comment.