Skip to content

Commit

Permalink
update sendNotification when community and beneficiary is added (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva committed May 23, 2023
1 parent b95d562 commit f12c639
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 14 additions & 3 deletions packages/core/src/subscriber/chainSubscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,13 @@ class ChainSubscribers {
if (user) {
await sendNotification(
[user.toJSON()],
NotificationType.COMMUNITY_CREATED
NotificationType.COMMUNITY_CREATED,
true,
true,
{
communityId:
community[1][0].id,
}
);
}
}
Expand All @@ -214,7 +220,7 @@ class ChainSubscribers {
if (parsedLog.name === 'BeneficiaryAdded') {
const communityAddress = log.address;
const community = this.communities.get(communityAddress);
const userAddress = parsedLog.args[0];
const userAddress = parsedLog.args[1];

if (community) {
utils.cache.cleanBeneficiaryCache(community);
Expand All @@ -229,7 +235,12 @@ class ChainSubscribers {
if (user) {
await sendNotification(
[user.toJSON()],
NotificationType.BENEFICIARY_ADDED
NotificationType.BENEFICIARY_ADDED,
true,
true,
{
communityId: community,
}
);
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/utils/pushNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ export async function sendNotification(
type: NotificationType,
isWallet: boolean = true,
isWebApp: boolean = true,
params?: object,
) {
// registry notification
await models.appNotification.bulkCreate(users.map(el => ({
userId: el.id,
type,
isWallet,
isWebApp,
params,
})));

// filter users that have walletPNT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ describe('Microcredit', () => {
userId: user.id,
type: NotificationType.LOAN_ADDED,
isWallet: true,
isWebApp: true
isWebApp: true,
params: undefined
}]
);
});
Expand Down

0 comments on commit f12c639

Please sign in to comment.