|
@@ -39,10 +39,11 @@ const sentMessage = async (req, res, next) => {
|
|
const user = req.user;
|
|
const user = req.user;
|
|
const userId = user.id;
|
|
const userId = user.id;
|
|
const companion = await UserModel.findById(id);
|
|
const companion = await UserModel.findById(id);
|
|
- const isUser = await ChatModel.getByField(id, userId);
|
|
|
|
- const isCompanion = await ChatModel.getByField(userId, id);
|
|
|
|
|
|
+ const isChat = await ChatModel.getByField(id, userId);
|
|
|
|
+ const isCompanionChat = await ChatModel.getByField(userId, id);
|
|
const { name, lastName, avatarUrl, color, number } = user;
|
|
const { name, lastName, avatarUrl, color, number } = user;
|
|
- if (companion && isUser && isCompanion) {
|
|
|
|
|
|
+
|
|
|
|
+ if (companion && isChat && isCompanionChat) {
|
|
const newMessage = await MessageModel.add({
|
|
const newMessage = await MessageModel.add({
|
|
message,
|
|
message,
|
|
name,
|
|
name,
|
|
@@ -63,6 +64,10 @@ const sentMessage = async (req, res, next) => {
|
|
companionId: userId,
|
|
companionId: userId,
|
|
owner: id,
|
|
owner: id,
|
|
});
|
|
});
|
|
|
|
+ const { total } = await MessageModel.getList(userId, {});
|
|
|
|
+ await ChatModel.update(isChat._id, { total });
|
|
|
|
+ const { total: Total } = await MessageModel.getList(id, {});
|
|
|
|
+ await ChatModel.update(isCompanionChat._id, { total: Total });
|
|
return res.status(201).json({
|
|
return res.status(201).json({
|
|
status: 'success',
|
|
status: 'success',
|
|
code: 201,
|
|
code: 201,
|