diff --git a/controllers/saveMessages.js b/controllers/saveMessages.js index 02b48e3..3e093f9 100644 --- a/controllers/saveMessages.js +++ b/controllers/saveMessages.js @@ -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"); @@ -30,4 +15,4 @@ const saveMessage = async (req, res) => { } }; -export default saveMessage; +export default saveMessage; \ No newline at end of file diff --git a/index.js b/index.js index ec88906..bc9f7c7 100644 --- a/index.js +++ b/index.js @@ -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 }; diff --git a/servises/getHistoryMessages.js b/servises/getHistoryMessages.js index 9c5dffe..4ef1694 100644 --- a/servises/getHistoryMessages.js +++ b/servises/getHistoryMessages.js @@ -17,4 +17,4 @@ const getChatHistory = async (user1, user2) => { return chatHistory; }; -export default getChatHistory; +export default getChatHistory; \ No newline at end of file