Skip to content

Commit 748de81

Browse files
authored
Merge pull request #229 from layerx-labs/dev
BEPRO 2.29
2 parents 4dddd4e + 9c23b54 commit 748de81

19 files changed

+361
-101
lines changed

src/actions/get-bounty-closed-event.ts

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
178178

179179
const {tokenAmount, fundingAmount, rewardAmount, rewardToken, transactional} = bounty;
180180

181-
const targets = [(await dbBounty.getUser({
182-
attributes: ["email", "id"],
183-
include: [{association: "user_settings"}]
184-
})).get()]
185-
186181
const AnalyticsEvent = {
187182
name: AnalyticEventName.BOUNTY_CLOSED,
188183
params: {
@@ -197,30 +192,7 @@ export async function action(block: DecodedLog, query?: EventsQuery): Promise<Ev
197192
}
198193
};
199194

200-
const NotificationEvent = {
201-
name: AnalyticEventName.NOTIF_TASK_CLOSED,
202-
params: {
203-
targets,
204-
task: {
205-
title: dbBounty.title,
206-
id: dbBounty.id,
207-
createdAt: dbBounty.createdAt,
208-
network: dbBounty.network.name,
209-
link: `${dbBounty.network.name}/task/${dbBounty.id}`
210-
},
211-
proposal: {
212-
id: dbProposal.id,
213-
link: `${dbBounty.network.name}/task/${dbBounty.id}/proposal/${dbProposal.id}`,
214-
},
215-
deliverable: {
216-
title: deliverable.title,
217-
id: deliverable.id,
218-
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbProposal.id}`
219-
},
220-
}
221-
}
222-
223-
Push.events([AnalyticsEvent, NotificationEvent]);
195+
Push.events([AnalyticsEvent]);
224196

225197
return eventsProcessed;
226198
}

src/actions/get-bounty-created-event.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {Push} from "../services/analytics/push";
2222
import {AnalyticEventName} from "../services/analytics/types/events";
2323
import {getDeveloperAmount} from "src/modules/calculate-distributed-amounts";
2424
import {getCoinIconByChainAndContractAddress} from "src/services/coingecko";
25+
import { subscribeUserToTask } from "src/utils/notifications/subscribe-user-to-task";
2526

2627

2728
export const name = "getBountyCreatedEvents";
@@ -148,6 +149,8 @@ export async function action(block: DecodedLog<BountyCreatedEvent['returnValues'
148149

149150
await dbBounty.save();
150151

152+
await subscribeUserToTask(dbBounty.id, dbBounty.user.address!);
153+
151154
updateLeaderboardBounties();
152155
updateBountiesHeader();
153156

@@ -182,6 +185,7 @@ export async function action(block: DecodedLog<BountyCreatedEvent['returnValues'
182185
? AnalyticEventName.NOTIF_TASK_FUNDING_CREATED
183186
: AnalyticEventName.NOTIF_TASK_CREATED,
184187
params: {
188+
bountyId: dbBounty.id,
185189
creator: {
186190
address: dbBounty.user?.address,
187191
username: dbBounty.user?.handle,

src/actions/get-proposal-created-event.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {NETWORK_NOT_FOUND} from "../utils/messages.const";
1313
import {Push} from "../services/analytics/push";
1414
import {AnalyticEventName} from "../services/analytics/types/events";
1515
import updateSeoCardBounty from "src/modules/handle-seo-card";
16+
import { subscribeUserToTask } from "src/utils/notifications/subscribe-user-to-task";
1617

1718
export const name = "getBountyProposalCreatedEvents";
1819
export const schedule = "*/13 * * * *";
@@ -88,6 +89,8 @@ export async function action(block: DecodedLog<BountyProposalCreatedEvent['retur
8889
sendMessageToTelegramChannels(BOUNTY_STATE_CHANGED(dbBounty.state, dbBounty));
8990
}
9091

92+
await subscribeUserToTask(dbBounty.id, dbBounty.user.address!);
93+
9194
updateLeaderboardProposals();
9295
updateSeoCardBounty(dbBounty.id, name);
9396

@@ -109,6 +112,7 @@ export async function action(block: DecodedLog<BountyProposalCreatedEvent['retur
109112
const NotificationEvent = {
110113
name: AnalyticEventName.NOTIF_PROPOSAL_OPEN,
111114
params: {
115+
bountyId: dbBounty.id,
112116
creator: {
113117
address: createProposal.creator,
114118
username: createProposal.handle,

src/actions/get-pullrequest-created-event.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {DELIVERABLE_OPEN} from "../integrations/telegram/messages";
1111
import {Push} from "../services/analytics/push";
1212
import {AnalyticEventName} from "../services/analytics/types/events";
1313
import updateSeoCardBounty from "src/modules/handle-seo-card";
14+
import { subscribeUserToTask } from "src/utils/notifications/subscribe-user-to-task";
1415

1516
export const name = "getBountyPullRequestCreatedEvents";
1617
export const schedule = "*/10 * * * *";
@@ -33,7 +34,7 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
3334

3435
const dbBounty = await db.issues.findOne({
3536
where: {contractId: bountyId, network_id: network.id},
36-
include: [{association: "network"}, {association: "chain"}]
37+
include: [{association: "network"}, {association: "chain"}, {association: "user"}]
3738
});
3839

3940
if (!dbBounty) {
@@ -61,15 +62,15 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
6162
dbDeliverable.bountyId = bounty.id
6263
await dbDeliverable.save();
6364

65+
await subscribeUserToTask(dbBounty.id, dbBounty.user.address!);
66+
6467
updateSeoCardBounty(dbBounty.id, name);
6568

6669
eventsProcessed[network.name!] = {
6770
[dbBounty.id!.toString()]: {bounty: dbBounty, eventBlock: parseLogWithContext(block)}
6871
};
6972

7073
sendMessageToTelegramChannels(DELIVERABLE_OPEN(dbBounty, dbDeliverable, dbDeliverable.id));
71-
72-
const targets = [(await dbBounty.getUser({attributes: ["email", "id"], include:[{ association: "user_settings" }] })).get()]
7374

7475
const AnalyticEvent = {
7576
name: AnalyticEventName.PULL_REQUEST_OPEN,
@@ -82,30 +83,7 @@ export async function action(block: DecodedLog<BountyPullRequestCreatedEvent['re
8283
}
8384
}
8485

85-
const NotificationEvent = {
86-
name: AnalyticEventName.NOTIF_DELIVERABLE_CREATED,
87-
params: {
88-
targets,
89-
creator: {
90-
address: dbDeliverable.user.address,
91-
id: dbDeliverable.user.id,
92-
username: dbDeliverable.user.handle,
93-
},
94-
task: {
95-
id: dbDeliverable.bountyId,
96-
title: dbBounty.title,
97-
network: dbBounty.network.name,
98-
},
99-
deliverable: {
100-
title: dbDeliverable.title,
101-
id: dbDeliverable.id,
102-
createdAt: dbDeliverable.createdAt,
103-
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbDeliverable.id}`
104-
}
105-
}
106-
}
107-
108-
Push.events([AnalyticEvent, NotificationEvent])
86+
Push.events([AnalyticEvent]);
10987

11088
return eventsProcessed;
11189
}

src/actions/get-pullrequest-ready-for-review.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {BOUNTY_STATE_CHANGED} from "../integrations/telegram/messages";
1010
import {Push} from "../services/analytics/push";
1111
import {AnalyticEventName} from "../services/analytics/types/events";
1212
import updateSeoCardBounty from "src/modules/handle-seo-card";
13-
import {Op} from "sequelize";
13+
import {Op, Sequelize} from "sequelize";
1414

1515
export const name = "getBountyPullRequestReadyForReviewEvents";
1616
export const schedule = "*/12 * * * *";
@@ -22,7 +22,6 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
2222

2323
const {returnValues: {bountyId, pullRequestId}, connection, address, chainId} = block;
2424

25-
2625
const bounty = await getBountyFromChain(connection, address, bountyId, name);
2726
if (!bounty)
2827
return eventsProcessed;
@@ -42,25 +41,23 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
4241
return eventsProcessed;
4342
}
4443

45-
4644
const pullRequest = bounty.pullRequests[pullRequestId];
4745

4846
const dbDeliverable = await db.deliverables.findOne({
49-
where: {id: pullRequest.cid},
47+
where: {id: pullRequest.cid, markedReadyForReview: false},
5048
include: {association: 'user'}
51-
})
49+
});
5250

5351
if (!dbDeliverable) {
5452
logger.warn(`${name} No deliverable found with "draft" and id ${pullRequest.cid}, maybe it was already parsed?`);
5553
return eventsProcessed;
5654
}
5755

58-
dbDeliverable.canceled = pullRequest.canceled
59-
dbDeliverable.markedReadyForReview = pullRequest?.ready
56+
dbDeliverable.canceled = pullRequest.canceled;
57+
dbDeliverable.markedReadyForReview = pullRequest?.ready;
6058

6159
await dbDeliverable.save();
6260

63-
6461
if (!["canceled", "closed", "proposal"].includes(dbBounty.state!)) {
6562
dbBounty.state = "ready";
6663
await dbBounty.save();
@@ -77,12 +74,29 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
7774
(async () => {
7875
const owner = await dbBounty!.getUser({attributes: ["email", "id"], include:[{ association: "user_settings" }] });
7976

80-
const curators = await dbBounty!.network.getCurators({
81-
include: [{association: "user", attributes: ["email", "id"], include:[{association: "user_settings"}]}],
82-
where: {userId: {[Op.not]: owner.id }, isCurrentlyCurator: true}
77+
const curators = await db.curators.findAll({
78+
include: [
79+
{
80+
association: "user",
81+
required: true,
82+
attributes: ["email", "id"],
83+
where: {
84+
id: {
85+
[Op.not]: owner.id
86+
},
87+
},
88+
on: Sequelize.where(Sequelize.fn("lower", Sequelize.col("curators.address")),
89+
"=",
90+
Sequelize.fn("lower", Sequelize.col("user.address"))),
91+
}
92+
],
93+
where: {
94+
networkId: dbBounty.network_id,
95+
isCurrentlyCurator: true
96+
}
8397
});
8498

85-
const targets = curators.map(curators => curators.user.get())
99+
const targets = curators.map(curators => curators.user);
86100

87101
const AnalyticEvent = {
88102
name: AnalyticEventName.PULL_REQUEST_READY,
@@ -92,12 +106,13 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
92106
deliverableId: dbDeliverable.id, deliverableContractId: pullRequestId,
93107
actor: pullRequest.creator,
94108
}
95-
}
109+
};
96110

97111
const NotificationEvent = {
98112
name: AnalyticEventName.NOTIF_DELIVERABLE_READY,
99113
params: {
100114
targets: [...targets, owner],
115+
bountyId: dbBounty.id,
101116
creator: {
102117
address: dbDeliverable.user.address,
103118
id: dbDeliverable.user.id,
@@ -114,9 +129,9 @@ export async function action(block: DecodedLog<BountyPullRequestReadyForReviewEv
114129
link: `${dbBounty.network.name}/task/${dbBounty.id}/deliverable/${dbDeliverable.id}`
115130
}
116131
}
117-
}
132+
};
118133

119-
Push.events([AnalyticEvent, NotificationEvent])
134+
Push.events([AnalyticEvent, NotificationEvent]);
120135
})()
121136

122137

src/db/models/init-models.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import { network_tokens as _network_tokens } from "./network_tokens";
3333
import type { network_tokensAttributes, network_tokensCreationAttributes } from "./network_tokens";
3434
import { networks as _networks } from "./networks";
3535
import type { networksAttributes, networksCreationAttributes } from "./networks";
36+
import { notification_settings as _notification_settings } from "./notification_settings";
37+
import type { notification_settingsAttributes, notification_settingsCreationAttributes } from "./notification_settings";
3638
import { notifications as _notifications } from "./notifications";
3739
import type { notificationsAttributes, notificationsCreationAttributes } from "./notifications";
3840
import { points_base as _points_base } from "./points_base";
@@ -72,6 +74,7 @@ export {
7274
_merge_proposals as merge_proposals,
7375
_network_tokens as network_tokens,
7476
_networks as networks,
77+
_notification_settings as notification_settings,
7578
_notifications as notifications,
7679
_points_base as points_base,
7780
_points_events as points_events,
@@ -119,6 +122,8 @@ export type {
119122
network_tokensCreationAttributes,
120123
networksAttributes,
121124
networksCreationAttributes,
125+
notification_settingsAttributes,
126+
notification_settingsCreationAttributes,
122127
notificationsAttributes,
123128
notificationsCreationAttributes,
124129
points_baseAttributes,
@@ -159,6 +164,7 @@ export function initModels(sequelize: Sequelize) {
159164
const merge_proposals = _merge_proposals.initModel(sequelize);
160165
const network_tokens = _network_tokens.initModel(sequelize);
161166
const networks = _networks.initModel(sequelize);
167+
const notification_settings = _notification_settings.initModel(sequelize);
162168
const notifications = _notifications.initModel(sequelize);
163169
const points_base = _points_base.initModel(sequelize);
164170
const points_events = _points_events.initModel(sequelize);
@@ -240,6 +246,8 @@ export function initModels(sequelize: Sequelize) {
240246
users.hasMany(issues, { as: "issues", foreignKey: "userId"});
241247
kyc_sessions.belongsTo(users, { as: "user", foreignKey: "user_id"});
242248
users.hasMany(kyc_sessions, { as: "kyc_sessions", foreignKey: "user_id"});
249+
notification_settings.belongsTo(users, { as: "user", foreignKey: "userId"});
250+
users.hasOne(notification_settings, { as: "notification_setting", foreignKey: "userId"});
243251
notifications.belongsTo(users, { as: "user", foreignKey: "userId"});
244252
users.hasMany(notifications, { as: "notifications", foreignKey: "userId"});
245253
points_events.belongsTo(users, { as: "user", foreignKey: "userId"});
@@ -267,6 +275,7 @@ export function initModels(sequelize: Sequelize) {
267275
merge_proposals: merge_proposals,
268276
network_tokens: network_tokens,
269277
networks: networks,
278+
notification_settings: notification_settings,
270279
notifications: notifications,
271280
points_base: points_base,
272281
points_events: points_events,

0 commit comments

Comments
 (0)