Skip to content

Commit

Permalink
feat(firewall): revert tabcoins earnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafatcb committed Jul 29, 2024
1 parent 7afa252 commit 1e959ad
Show file tree
Hide file tree
Showing 3 changed files with 474 additions and 2 deletions.
1 change: 1 addition & 0 deletions models/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,4 +989,5 @@ export default Object.freeze({
findWithStrategy,
create,
update,
creditOrDebitTabCoins,
});
26 changes: 24 additions & 2 deletions models/firewall/rules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { TooManyRequestsError } from 'errors';
import database from 'infra/database.js';
import content from 'models/content';
import event from 'models/event.js';
import notification from 'models/notification';

Expand Down Expand Up @@ -115,7 +116,10 @@ async function createContentTextRootRuleSideEffect(context) {
},
});

await sendContentTextNotification(results.rows, createdEvent);
await Promise.allSettled([
undoContentsTabcoins(results.rows, createdEvent),
sendContentTextNotification(results.rows, createdEvent),
]);
}

async function createContentTextChildRule(context) {
Expand Down Expand Up @@ -154,7 +158,25 @@ async function createContentTextChildRuleSideEffect(context) {
},
});

await sendContentTextNotification(results.rows, createdEvent);
await Promise.allSettled([
undoContentsTabcoins(results.rows, createdEvent),
sendContentTextNotification(results.rows, createdEvent),
]);
}

async function undoContentsTabcoins(contentRows, createdEvent) {
for (const contentObject of contentRows) {
await content.creditOrDebitTabCoins(
{
...contentObject,
status: contentObject.status_before_update,
},
contentObject,
{
eventId: createdEvent.id,
},
);
}
}

async function sendContentTextNotification(contentRows, event) {
Expand Down
Loading

0 comments on commit 1e959ad

Please sign in to comment.