-
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
6 changed files
with
91 additions
and
24 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,3 @@ | ||
export const sendMessage = async (req, res) => { | ||
console.log("message sent", req.params.id); | ||
}; |
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,24 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const conversationSchema = new mongoose.Schema( | ||
{ | ||
participants: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User", | ||
}, | ||
], | ||
messages: [ | ||
{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "Message", | ||
default: [], | ||
}, | ||
], | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const Conversation = mongoose.model("Conversation", conversationSchema); | ||
|
||
export default Conversation; |
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,26 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const messageSchema = new mongoose.Schema( | ||
{ | ||
senderId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
receiverId: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: "User", | ||
required: true, | ||
}, | ||
message: { | ||
type: String, | ||
required: true, | ||
}, | ||
}, | ||
// createdAt, updatedAt when timestamp is true > message.createdAt, message.updatedAt | ||
{ timestamps: true } | ||
); | ||
|
||
const Message = mongoose.model("Message", messageSchema); | ||
|
||
export default Message; |
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
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,8 @@ | ||
import express from "express"; | ||
import { sendMessage } from "../controllers/message.controller.js"; | ||
|
||
const router = express.Router(); | ||
|
||
router.post("/send/:id", sendMessage); | ||
|
||
export default router; |
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