Skip to content

Commit f6e4fe6

Browse files
Merge pull request #107 from Giveth/Release
Release 2.3.0
2 parents 1cc27b0 + d33adbb commit f6e4fe6

21 files changed

+1049
-44
lines changed

LICENSE

+674-21
Large diffs are not rendered by default.

config/test.env

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ GIVETH_IO_THIRD_PARTY_MICRO_SERVICE=givethio
2323
GIV_ECONOMY_THIRD_PARTY_SECRET=secret
2424
GIV_ECONOMY_THIRD_PARTY_MICRO_SERVICE=giveconomy-notification-service
2525

26+
NOTIFY_REWARD_THIRD_PARTY_SECRET=secret
27+
NOTIFY_REWARD_THIRD_PARTY_MICRO_SERVICE=notifyreward
28+
2629
# OPTIONAL - force logging to stdout when the value is true
2730
LOG_STDOUT=false
2831

funding.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"opRetro": {
3+
"projectId": "0xe434930e189c807b137ff0d8e2fa6a95eaa57dde574143a02ca0d7fb31a40bea"
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm"
2+
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
3+
import { MICRO_SERVICES } from '../src/utils/utils';
4+
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
5+
6+
const NotifyRewardAmountNotificationType = [
7+
{
8+
name: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
9+
description: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT,
10+
microService: MICRO_SERVICES.givethio,
11+
category: NOTIFICATION_CATEGORY.GENERAL,
12+
schemaValidator: SCHEMA_VALIDATORS_NAMES.NOTIFY_REWARD_AMOUNT,
13+
title: "Notify reward report",
14+
}
15+
]
16+
17+
export class seedNotificationTypeForNotifyRewardAmount1718888344202 implements MigrationInterface {
18+
public async up(queryRunner: QueryRunner): Promise<void> {
19+
await queryRunner.manager.save(NotificationType, NotifyRewardAmountNotificationType);
20+
}
21+
22+
public async down(queryRunner: QueryRunner): Promise<void> {
23+
await queryRunner.query(
24+
`DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT};`,
25+
);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm"
2+
import { NOTIFICATION_CATEGORY } from '../src/types/general';
3+
import { MICRO_SERVICES } from '../src/utils/utils';
4+
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
5+
import { NOTIFICATIONS_EVENT_NAMES } from '../src/types/notifications';
6+
7+
const EmailConfirmationNotificationType = [
8+
{
9+
name: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
10+
description: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
11+
microService: MICRO_SERVICES.givethio,
12+
category: NOTIFICATION_CATEGORY.ORTTO,
13+
schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION,
14+
}
15+
]
16+
17+
export class seedNotificationTypeForSendEmailConfirmation1719224595366 implements MigrationInterface {
18+
public async up(queryRunner: QueryRunner): Promise<void> {
19+
await queryRunner.manager.save(NotificationType, EmailConfirmationNotificationType);
20+
}
21+
22+
public async down(queryRunner: QueryRunner): Promise<void> {
23+
await queryRunner.query(
24+
`DELETE FROM notification_type WHERE "name" = 'Send email confirmation';`,
25+
);
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm"
2+
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
3+
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
4+
import { MICRO_SERVICES } from '../src/utils/utils';
5+
6+
const OnboardingNotificationType = [
7+
{
8+
name: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
9+
description: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
10+
microService: MICRO_SERVICES.givethio,
11+
category: NOTIFICATION_CATEGORY.ORTTO,
12+
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUBSCRIBE_ONBOARDING,
13+
}
14+
]
15+
16+
export class seedNotificationTypeForOnboardingGuide1719410008992 implements MigrationInterface {
17+
public async up(queryRunner: QueryRunner): Promise<void> {
18+
await queryRunner.manager.save(NotificationType, OnboardingNotificationType);
19+
}
20+
21+
public async down(queryRunner: QueryRunner): Promise<void> {
22+
await queryRunner.query(
23+
`DELETE FROM notification_type WHERE "name" = 'Subscribe onboarding';`,
24+
);
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm";
2+
import { MICRO_SERVICES } from '../src/utils/utils';
3+
import { NOTIFICATION_CATEGORY } from '../src/types/general';
4+
5+
export class changeMicroserviceAndCategoryOfNotifyRewardNotificationType1720553769343 implements MigrationInterface {
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`
8+
UPDATE notification_type
9+
SET "microService" = '${MICRO_SERVICES.notifyReward}',
10+
category = '${NOTIFICATION_CATEGORY.ORTTO}'
11+
WHERE name = 'Notify reward amount';
12+
`);
13+
}
14+
15+
public async down(queryRunner: QueryRunner): Promise<void> {
16+
await queryRunner.query(`
17+
UPDATE notification_type
18+
SET "microService" = '${MICRO_SERVICES.givethio}',
19+
categoty = '${NOTIFICATION_CATEGORY.GENERAL}'
20+
WHERE name = 'Notify reward amount';
21+
`);
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { MigrationInterface, QueryRunner } from "typeorm"
2+
3+
export class seedThirdPartyForNotifyReward1720828190666 implements MigrationInterface {
4+
public async up(queryRunner: QueryRunner): Promise<void> {
5+
if (
6+
process.env.NODE_ENV === 'test' ||
7+
process.env.NODE_ENV === 'development'
8+
) {
9+
// Create third part record for notifyreward in development and test ENVs
10+
await queryRunner.query(`
11+
INSERT INTO third_party(
12+
"microService", secret, "isActive")
13+
VALUES
14+
('notifyreward', 'secret', true)
15+
;
16+
`);
17+
}
18+
}
19+
20+
public async down(queryRunner: QueryRunner): Promise<void> {
21+
await queryRunner.query(`
22+
DELETE FROM third_party
23+
WHERE "microService" = 'notifyreward';
24+
`);
25+
}
26+
27+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "notification-venter",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

src/entities/notificationType.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,17 @@ import {
44
CreateDateColumn,
55
Entity,
66
Index,
7-
JoinTable,
8-
ManyToOne,
97
OneToMany,
108
PrimaryGeneratedColumn,
11-
RelationId,
129
UpdateDateColumn,
1310
} from 'typeorm';
14-
import { NOTIFICATION_CATEGORY } from '../types/general';
1511
import { NotificationSetting } from './notificationSetting';
1612

1713
// Export Object with Schemas to N1 lookup
1814
export const SCHEMA_VALIDATORS_NAMES = {
15+
SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation',
1916
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
17+
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
2018
SUPERFLUID: 'userSuperTokensCritical',
2119
ADMIN_MESSAGE: 'adminMessage',
2220
RAW_HTML_BROADCAST: 'rawHtmlBroadcast',
@@ -68,6 +66,8 @@ export const SCHEMA_VALIDATORS_NAMES = {
6866
PROJECT_HAS_A_NEW_RANK: 'projectHasANewRank',
6967
PROJECT_HAS_RISEN_IN_THE_RANK: 'projectHasRisenInTheRank',
7068
YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank',
69+
70+
NOTIFY_REWARD_AMOUNT: 'notifyRewardAmount',
7171
};
7272
export type HtmlTemplate = { type: string; content: string; href?: string }[];
7373

src/routes/v1/notificationRouter.test.ts

+72
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getAccessTokenForMockAuthMicroService,
66
getGivEconomyBasicAuth,
77
getGivethIoBasicAuth,
8+
getNotifyRewardBasicAuth,
89
serverUrl,
910
sleep,
1011
} from '../../../test/testUtils';
@@ -2092,6 +2093,77 @@ function sendNotificationTestCases() {
20922093
const createdNotification = await findNotificationByTrackId(trackId);
20932094
assert.equal(createdNotification?.createdAt.getTime(), creationTime);
20942095
});
2096+
2097+
it('should create *Notify reward amount* notification, success', async () => {
2098+
const data = {
2099+
eventName: "Notify reward amount",
2100+
sendEmail: true,
2101+
sendSegment: true,
2102+
creationTime: 1667992708000,
2103+
2104+
segment: {
2105+
payload: {
2106+
round: 10,
2107+
date: "1667992708000",
2108+
amount: "12134",
2109+
contractAddress: "0xsfglsjfdflk",
2110+
farm: "test farm",
2111+
message: "test message",
2112+
network: "ethereum",
2113+
script: "test script",
2114+
transactionHash: "test txhash"
2115+
}
2116+
}
2117+
};
2118+
2119+
const result = await axios.post(sendNotificationUrl, data, {
2120+
headers: {
2121+
authorization: getNotifyRewardBasicAuth(),
2122+
},
2123+
});
2124+
2125+
assert.equal(result.status, 200);
2126+
assert.isOk(result.data);
2127+
assert.isTrue(result.data.success);
2128+
});
2129+
it('should create *Notify reward amount* notification, failed invalid payload', async () => {
2130+
try {
2131+
const data = {
2132+
eventName: "Notify reward amount",
2133+
sendEmail: true,
2134+
sendSegment: true,
2135+
creationTime: 1667992708000,
2136+
2137+
segment: {
2138+
payload: {
2139+
round: 10,
2140+
date: "1667992708000",
2141+
amount: "12134",
2142+
contractAddress: "0xsfglsjfdflk",
2143+
farm: "test farm",
2144+
message: "test message",
2145+
network: "ethereum",
2146+
script: "test script",
2147+
transactionHash: "test txhash",
2148+
invalidField: "invalid data"
2149+
}
2150+
}
2151+
};
2152+
await axios.post(sendNotificationUrl, data, {
2153+
headers: {
2154+
authorization: getNotifyRewardBasicAuth(),
2155+
},
2156+
});
2157+
// If request doesn't fail, it means this test failed
2158+
assert.isTrue(false);
2159+
} catch (e: any) {
2160+
assert.equal(
2161+
e.response.data.message,
2162+
errorMessagesEnum.IMPACT_GRAPH_VALIDATION_ERROR.message,
2163+
);
2164+
assert.equal(e.response.data.description, '"segment.payload.invalidField" is not allowed');
2165+
}
2166+
});
20952167
}
20962168

20972169
function sendBulkNotificationsTestCases() {

src/routes/v1/notificationRouter.ts

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
} from '../../middlewares/authentication';
66
import { NotificationsController } from '../../controllers/v1/notificationsController';
77
import { sendStandardResponse } from '../../utils/responseUtils';
8+
import { logger } from '../../utils/logger';
89
import { createNewUserAddressIfNotExists } from '../../repositories/userAddressRepository';
910

1011
export const notificationRouter = express.Router();
@@ -22,6 +23,7 @@ notificationRouter.post(
2223
});
2324
return sendStandardResponse({ res, result });
2425
} catch (e) {
26+
logger.error('/thirdParty/notifications error', e);
2527
next(e);
2628
}
2729
},
@@ -41,6 +43,7 @@ notificationRouter.post(
4143
);
4244
return sendStandardResponse({ res, result });
4345
} catch (e) {
46+
logger.error('/thirdParty/notificationsBulk error', e);
4447
next(e);
4548
}
4649
},
@@ -65,6 +68,7 @@ notificationRouter.get(
6568
);
6669
return sendStandardResponse({ res, result });
6770
} catch (e) {
71+
logger.error('/notifications error', e);
6872
next(e);
6973
}
7074
},
@@ -85,6 +89,7 @@ notificationRouter.put(
8589
);
8690
return sendStandardResponse({ res, result });
8791
} catch (e) {
92+
logger.error('/notifications/read/:notificationId error', e);
8893
next(e);
8994
}
9095
},
@@ -100,6 +105,7 @@ notificationRouter.get(
100105
);
101106
return sendStandardResponse({ res, result });
102107
} catch (e) {
108+
logger.error('/notifications/countUnread/:walletAddress error', e);
103109
next(e);
104110
}
105111
},
@@ -120,6 +126,7 @@ notificationRouter.put(
120126
);
121127
return sendStandardResponse({ res, result });
122128
} catch (e) {
129+
logger.error('/notifications/readAll error', e);
123130
next(e);
124131
}
125132
},

src/routes/v1/notificationSettingsRouter.ts

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import express, { Request, Response } from 'express';
22
import { validateAuthMicroserviceJwt } from '../../middlewares/authentication';
33
import { NotificationSettingsController } from '../../controllers/v1/notificationSettingsController';
44
import { sendStandardResponse } from '../../utils/responseUtils';
5+
import { logger } from '../../utils/logger';
56

67
export const notificationSettingsRouter = express.Router();
78

@@ -25,6 +26,7 @@ notificationSettingsRouter.get(
2526
);
2627
return sendStandardResponse({ res, result });
2728
} catch (e) {
29+
logger.error('get /notification_settings error', e);
2830
next(e);
2931
}
3032
},
@@ -47,6 +49,7 @@ notificationSettingsRouter.put(
4749
);
4850
return sendStandardResponse({ res, result });
4951
} catch (e) {
52+
logger.error('/notification_settings/:id error', e);
5053
next(e);
5154
}
5255
},
@@ -68,6 +71,7 @@ notificationSettingsRouter.put(
6871
);
6972
return sendStandardResponse({ res, result });
7073
} catch (e) {
74+
logger.error('put /notification_settings error', e);
7175
next(e);
7276
}
7377
},

0 commit comments

Comments
 (0)