Skip to content

Commit

Permalink
fix(users): reset messages with pointsByMessageGivenAt (#3215)
Browse files Browse the repository at this point in the history
* fix(users): reset messages with pointsByMessageGivenAt

* fixup
  • Loading branch information
sogehige committed Jan 27, 2020
1 parent 2e953be commit 757b477
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/bot/users.ts
Expand Up @@ -157,7 +157,7 @@ class Users extends Core {
cb();
});
adminEndpoint(this.nsp, 'viewers::resetMessagesAll', async (cb) => {
await getRepository(User).update({}, { messages: 0 });
await getRepository(User).update({}, { messages: 0, pointsByMessageGivenAt: 0 });
cb();
});
adminEndpoint(this.nsp, 'viewers::resetWatchedTimeAll', async (cb) => {
Expand All @@ -172,12 +172,16 @@ class Users extends Core {
await getRepository(UserTip).clear();
cb();
});
adminEndpoint(this.nsp, 'viewers::save', async (viewer: UserInterface, cb) => {
adminEndpoint(this.nsp, 'viewers::save', async (viewer: Required<UserInterface>, cb) => {
try {
// recount sortAmount
for (const tip of viewer.tips) {
tip.sortAmount = currency.exchange(Number(tip.amount), tip.currency, 'EUR');
}

if (viewer.messages < viewer.pointsByMessageGivenAt) {
viewer.pointsByMessageGivenAt = viewer.messages;
}
await getRepository(User).save(viewer);
cb();
} catch (e) {
Expand Down

0 comments on commit 757b477

Please sign in to comment.