mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
refactor update the message to use .save - fix test
This commit is contained in:
@@ -66,8 +66,8 @@ describe('POST /members/flag-private-message/:messageId', () => {
|
||||
|
||||
await expect(receiver.post(`/members/flag-private-message/${sendersMessageInReceiversInbox.id}`))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: t('messageGroupChatFlagAlreadyReported'),
|
||||
});
|
||||
});
|
||||
|
||||
@@ -67,10 +67,12 @@ export default class InboxChatReporter extends ChatReporter {
|
||||
});
|
||||
}
|
||||
|
||||
updateMessageAndSave (message, updateFunc) {
|
||||
updateFunc(message);
|
||||
updateMessageAndSave (message, ...changedFields) {
|
||||
for (const changedField of changedFields) {
|
||||
message.markModified(changedField);
|
||||
}
|
||||
|
||||
return inboxLib.updateMessage(message);
|
||||
return message.save();
|
||||
}
|
||||
|
||||
flagInboxMessage (message) {
|
||||
@@ -81,16 +83,16 @@ export default class InboxChatReporter extends ChatReporter {
|
||||
throw new BadRequest(this.res.t('messageGroupChatFlagAlreadyReported'));
|
||||
}
|
||||
|
||||
return this.updateMessageAndSave(message, (m) => {
|
||||
m.flags[this.user._id] = true;
|
||||
m.flagCount = 1;
|
||||
});
|
||||
message.flags[this.user._id] = true;
|
||||
message.flagCount = 1;
|
||||
|
||||
return this.updateMessageAndSave(message, 'flags', 'flagCount');
|
||||
}
|
||||
|
||||
async markMessageAsReported (message) {
|
||||
return this.updateMessageAndSave(message, (m) => {
|
||||
m.reported = true;
|
||||
});
|
||||
message.reported = true;
|
||||
|
||||
return this.updateMessageAndSave(message, 'reported');
|
||||
}
|
||||
|
||||
async flag () {
|
||||
|
||||
@@ -36,9 +36,3 @@ export async function clearPMs (user) {
|
||||
Inbox.remove({ownerId: user._id}).exec(),
|
||||
]);
|
||||
}
|
||||
|
||||
export async function updateMessage (message) {
|
||||
await Inbox.update({
|
||||
id: message._id,
|
||||
}, message).exec();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user