Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yosi Miller authored and Yosi Miller committed Dec 28, 2023
1 parent b909cc1 commit d15f02c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
23 changes: 4 additions & 19 deletions controllers/saveMessages.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
/**
* An Express middleware function that saves a chat message to the database.
*
* @param {Object} req - The Express request object.
* @param {Object} res - The Express response object.
*
* The request object should have the following structure:
* - params: An object with the following properties:
* - senderId: The ID of the sender of the message.
* - gettingId: The ID of the recipient of the message.
* - body: An object with the following properties:
* - mas: The message to be saved.
*
* If the message is saved successfully, the function sends a response with a status code of 200 and a message of "Message saved to DB".
* If there is an error, the function sends a response with a status code of 500 and a message of "Error saving message to DB".
*/
import saveChatToDatabase from "../servises/savingMessage.js";
import socketController from "./socketController.js";

const saveMessage = async (req, res) => {
const { senderId, gettingId } = req.params;
const { mas } = req.body;
const {text, local_user, selectedUserId} = req.body;
console.log("∆", local_user, selectedUserId["*"])
try {
await saveChatToDatabase(senderId, gettingId, mas);
await saveChatToDatabase(local_user, selectedUserId["*"], text);
// Listens for new connections to the server.
// io.on("connection", socketController);
res.status(200).send("Message saved to DB");
Expand All @@ -30,4 +15,4 @@ const saveMessage = async (req, res) => {
}
};

export default saveMessage;
export default saveMessage;
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const io = new Server(server, {
app.get("/chat/:senderId/:gettingId", chatHistoryMesssages);

// this save the chat message to the DB when the user send message
app.post("/send/:senderId/:gettingId", saveMessage);
app.post("/send", saveMessage);

export default server;
export { io };
2 changes: 1 addition & 1 deletion servises/getHistoryMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const getChatHistory = async (user1, user2) => {
return chatHistory;
};

export default getChatHistory;
export default getChatHistory;

0 comments on commit d15f02c

Please sign in to comment.