mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Removed redundant code and changed like route to return only altered message
This commit is contained in:
@@ -4,7 +4,7 @@ import {
|
|||||||
translate as t,
|
translate as t,
|
||||||
} from '../../../../helpers/api-integration.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
|
|
||||||
describe('POST /chat', () => {
|
describe('POST /chat/:chatId/like', () => {
|
||||||
let user;
|
let user;
|
||||||
let api;
|
let api;
|
||||||
let group;
|
let group;
|
||||||
@@ -62,7 +62,7 @@ describe('POST /chat', () => {
|
|||||||
return api.post(`/groups/${group._id}/chat/${result.message.id}/like`);
|
return api.post(`/groups/${group._id}/chat/${result.message.id}/like`);
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
expect(result[0].likes[user._id]).to.equal(true);
|
expect(result.likes[user._id]).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ api.likeChat = {
|
|||||||
handler (req, res, next) {
|
handler (req, res, next) {
|
||||||
let user = res.locals.user;
|
let user = res.locals.user;
|
||||||
let groupId = req.params.groupId;
|
let groupId = req.params.groupId;
|
||||||
|
let message;
|
||||||
|
|
||||||
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
req.checkParams('groupId', res.t('groupIdRequired')).notEmpty();
|
||||||
req.checkParams('chatId', res.t('chatIdRequired')).notEmpty();
|
req.checkParams('chatId', res.t('chatIdRequired')).notEmpty();
|
||||||
@@ -124,7 +125,7 @@ api.likeChat = {
|
|||||||
Group.getGroup(user, groupId)
|
Group.getGroup(user, groupId)
|
||||||
.then((group) => {
|
.then((group) => {
|
||||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||||
let message = _.find(group.chat, {id: req.params.chatId});
|
message = _.find(group.chat, {id: req.params.chatId});
|
||||||
if (!message) throw new NotFound(res.t('messageGroupChatNotFound'));
|
if (!message) throw new NotFound(res.t('messageGroupChatNotFound'));
|
||||||
|
|
||||||
if (message.uuid === user._id) throw new NotFound(res.t('messageGroupChatLikeOwnMessage'));
|
if (message.uuid === user._id) throw new NotFound(res.t('messageGroupChatLikeOwnMessage'));
|
||||||
@@ -136,14 +137,11 @@ api.likeChat = {
|
|||||||
message.likes[user._id] = true;
|
message.likes[user._id] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
let messageIndex = group.chat.indexOf(message);
|
|
||||||
group.chat[messageIndex].likes = message.likes;
|
|
||||||
|
|
||||||
return group.save();
|
return group.save();
|
||||||
})
|
})
|
||||||
.then((group) => {
|
.then((group) => {
|
||||||
if (!group) throw new NotFound(res.t('groupNotFound'));
|
if (!group) throw new NotFound(res.t('groupNotFound'));
|
||||||
res.respond(200, group.chat);
|
res.respond(200, message);
|
||||||
})
|
})
|
||||||
.catch(next);
|
.catch(next);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user