Skip to content

Commit

Permalink
fix: error while create message
Browse files Browse the repository at this point in the history
fixes #107
  • Loading branch information
roman-ojha committed Jun 10, 2022
1 parent 0a5752c commit 429ab2b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MessagesListSingleMessage = (props) => {
if (resMessage.status !== 200) {
// const error = await resMessage.data;
} else {
const resData = await resMessage.data;
const resData = await resMessage.data.data;
// after getting message we will store that message into redux
dispatch(
currentUserMessageAction({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const MessageListSingleMessage = (props) => {
if (resMessage.status !== 200) {
// const error = await resMessage.data;
} else {
const resData = await resMessage.data;
const resData = await resMessage.data.data;
// after getting message we will store that message into redux
dispatch(
currentUserMessageAction({
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/ProfilePage/UserInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ const UserInfo = () => {
if (resMessage.status !== 200) {
// const error = await resMessage.data;
} else {
const resData = await resMessage.data;
const resData = await resMessage.data.data;
// after getting message we will store that message into redux
dispatch(
currentUserMessageAction({
messageToId: resData.messageToId,
messageToUserId: profilePageData.userID,
receiverPicture: profilePageData.picture,
roomID: resData.roomID,
// roomID: resData.roomID,
message: resData.message,
fetchedInnerMessage: true,
})
);
}
Expand Down
24 changes: 17 additions & 7 deletions controllers/message.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export default {
);
if (!userMessage) {
// if message doesn't exist already then we have to create a new message which would contain the empty message
const roomID = crypto.randomBytes(16).toString("hex");
// const roomID = crypto.randomBytes(16).toString("hex");
// generating new room id for those spacific user room to join on socket
const resSaveRootMsg = await userDetail.updateOne(
// creating and saving message to rootUser
Expand All @@ -151,7 +151,7 @@ export default {
$push: {
messages: {
messageToId: messageToId,
roomID: roomID,
// roomID: roomID,
message: [],
},
},
Expand All @@ -166,23 +166,33 @@ export default {
$push: {
messages: {
messageToId: rootUser.id,
roomID: roomID,
// roomID: roomID,
message: [],
},
},
}
);
if (resSaverReceiverMsg && resSaveRootMsg) {
return res
.status(200)
.json(<ResponseObject>{ success: true, msg: "message created" });
return res.status(200).json(<ResponseObject>{
success: true,
msg: "message created",
data: {
messageToId: messageToId,
message: [],
lastMessageOn: new Date(),
},
});
} else {
return res
.status(500)
.json(<ResponseObject>{ success: false, msg: "server error" });
}
}
return res.status(200).json(userMessage.messages[0]);
return res.status(200).json({
success: true,
msg: "Successful",
data: userMessage.messages[0],
});
} catch (err) {
return res.status(500).json(<ResponseObject>{
success: false,
Expand Down
8 changes: 4 additions & 4 deletions models/userMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const userMessages = {
type: String,
required: true,
},
roomID: {
type: String,
required: true,
},
// roomID: {
// type: String,
// required: true,
// },
message: [
{
senderId: {
Expand Down

0 comments on commit 429ab2b

Please sign in to comment.