From 200c4f96356a251eadf8e42d5b67304089c0b851 Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Wed, 19 Jun 2024 02:08:36 +0330 Subject: [PATCH 1/4] Add notify reward amount to notification types --- src/types/notifications.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/types/notifications.ts b/src/types/notifications.ts index b7c85bd..5eabd72 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -48,6 +48,8 @@ export enum NOTIFICATIONS_EVENT_NAMES { SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance', SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', CREATE_ORTTO_PROFILE = 'Create Ortto profile', + + NOTIFY_REWARD_AMOUNT = 'Notify reward amount', } export const ORTTO_EVENT_NAMES = { @@ -66,5 +68,6 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.VERIFICATION_FORM_REJECTED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING]: 'first-update-warning', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning', - [NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile' + [NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile', + [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount' } \ No newline at end of file From ad698ca5a904332e472d037633031567b02e12ac Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Wed, 19 Jun 2024 02:09:35 +0330 Subject: [PATCH 2/4] Add notify reward amount notification fields --- src/services/notificationService.ts | 13 +++++++++++++ src/validators/schemaValidators.ts | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 3b159aa..28a0472 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -163,6 +163,19 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES "str:cm:userid": payload.userId?.toString(), } break + case NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT: + attributes = { + "int:cm:round": payload.round, + "str:cm:date": payload.date, + "str:cm:amount": payload.amount, + "str:cm:contractaddress": payload.contractAddress, + "str:cm:farm": payload.farm, + "str:cm:message": payload.message, + "str:cm:network": payload.network, + "str:cm:script": payload.script, + "str:cm:transactionhash": payload.transactionHash, + } + break default: logger.debug('activityCreator() invalid event name', orttoEventName) return; diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 7540433..7bbb374 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -86,6 +86,10 @@ export const sendNotificationValidator = Joi.object({ // Project update update: Joi.string(), + + // Notify reward attributes + contractAddress: Joi.string(), + farm: Joi.string(), }), }), }); From 2596137a69bc8917e92faaeab0a0d2be39ab509a Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Fri, 21 Jun 2024 00:47:47 +0330 Subject: [PATCH 3/4] Add new migration for notify reward amount notification type --- ...edNotificationTypeForNotifyRewardAmount.ts | 27 +++++++++++++++++++ src/entities/notificationType.ts | 2 ++ src/types/general.ts | 5 +++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 migrations/1718888344202-seedNotificationTypeForNotifyRewardAmount.ts diff --git a/migrations/1718888344202-seedNotificationTypeForNotifyRewardAmount.ts b/migrations/1718888344202-seedNotificationTypeForNotifyRewardAmount.ts new file mode 100644 index 0000000..0cb4861 --- /dev/null +++ b/migrations/1718888344202-seedNotificationTypeForNotifyRewardAmount.ts @@ -0,0 +1,27 @@ +import { MigrationInterface, QueryRunner } from "typeorm" +import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general'; +import { MICRO_SERVICES } from '../src/utils/utils'; +import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType'; + +const NotifyRewardAmountNotificationType = [ + { + name: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT, + description: NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT, + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.NOTIFY_REWARD_AMOUNT, + schemaValidator: SCHEMA_VALIDATORS_NAMES.NOTIFY_REWARD_AMOUNT, + title: "Notify reward report", + } +] + +export class seedNotificationTypeForNotifyRewardAmount1718888344202 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.manager.save(NotificationType, NotifyRewardAmountNotificationType); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT};`, + ); + } +} diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index 888600d..608a102 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -68,6 +68,8 @@ export const SCHEMA_VALIDATORS_NAMES = { PROJECT_HAS_A_NEW_RANK: 'projectHasANewRank', PROJECT_HAS_RISEN_IN_THE_RANK: 'projectHasRisenInTheRank', YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank', + + NOTIFY_REWARD_AMOUNT: 'notifyRewardAmount', }; export type HtmlTemplate = { type: string; content: string; href?: string }[]; diff --git a/src/types/general.ts b/src/types/general.ts index 62516a5..34e0998 100644 --- a/src/types/general.ts +++ b/src/types/general.ts @@ -11,7 +11,8 @@ export enum NOTIFICATION_CATEGORY { GIV_ECONOMY = 'givEconomy', SUPPORTED_PROJECTS = 'supportedProjects', GIV_POWER = 'givPower', - ORTTO = 'ortto' + ORTTO = 'ortto', + NOTIFY_REWARD_AMOUNT = 'notifyRewardAmount', } export enum NOTIFICATION_TYPE_NAMES { @@ -52,4 +53,6 @@ export enum NOTIFICATION_TYPE_NAMES { PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank', YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank', CREATE_ORTTO_PROFILE = 'Create Ortto profile', + + NOTIFY_REWARD_AMOUNT = 'Notify reward amount', } From 347a07277301e408b1b56d8645a83989d4f03bfb Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Tue, 2 Jul 2024 03:20:18 +0330 Subject: [PATCH 4/4] Add notifyRewardAmount validator to SEGMENT_METADATA_SCHEMA_VALIDATOR --- .../validators/segmentAndMetadataValidators.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index c932ca1..901e790 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -166,6 +166,18 @@ const createOrttoProfileSegmentSchema = Joi.object({ userId: Joi.number().required() }) +const notifyRewardAmountSegmentSchema = Joi.object({ + round: Joi.number().required(), + date: Joi.string().required(), + amount: Joi.string().required(), + contractAddress: Joi.string().required(), + farm: Joi.string().required(), + message: Joi.string().required(), + network: Joi.string().required(), + script: Joi.string().required(), + transactionHash: Joi.string().required(), +}) + export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { [key: string]: { segment: ObjectSchema | null; @@ -335,6 +347,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { metadata: projectTitleProjectLinkSchema, segment: null, }, + notifyRewardAmount: { + metadata: null, + segment: notifyRewardAmountSegmentSchema, + }, }; function throwHttpErrorIfJoiValidatorFails(