diff --git a/models/Conversation.js b/models/Conversation.js new file mode 100644 index 0000000..3afe8de --- /dev/null +++ b/models/Conversation.js @@ -0,0 +1,31 @@ +// External Module: +const mongoose = require("mongoose"); + +// Make Conversation Schema: +const ConversationSchema = mongoose.Schema( + { + creator: { + id: mongoose.Types.ObjectId, + name: String, + avatar: String, + }, + participant: { + id: mongoose.Types.ObjectId, + name: String, + avatar: String, + }, + last_updated: { + type: Date, + default: Date.now, + }, + }, + { + timestamps: true, + } +); + +// Make Convertation Model: +const Conversation = mongoose.model("Conversation", ConversationSchema); + +// Model Export +module.exports = Conversation; diff --git a/models/Message.js b/models/Message.js new file mode 100644 index 0000000..2afa78d --- /dev/null +++ b/models/Message.js @@ -0,0 +1,37 @@ +// External Modules: +const mongoose = require("mongoose"); + +// Create Message Schema: +const MessageSchema = mongoose.Schema( + { + text: String, + attachment: [{ type: String }], + sender: { + id: mongoose.Types.ObjectId, + name: String, + avatar: String, + }, + receiver: { + id: mongoose.Types.ObjectId, + name: String, + avatar: String, + }, + date_time: { + type: Date, + defaul: Date.now, + }, + conversation_id: { + type: mongoose.Types.ObjectId, + required: true, + }, + }, + { + timestamps: true, + } +); + +// Create Message Model: +const Message = mongoose.model("Message", MessageSchema); + +// Export Model: +module.exports = Message;