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 f497ee2..fa12850 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -66,6 +66,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/services/notificationService.ts b/src/services/notificationService.ts index 73cee67..8e64221 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -164,6 +164,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/types/general.ts b/src/types/general.ts index 83b5a09..a267f31 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 { @@ -53,4 +54,6 @@ export enum NOTIFICATION_TYPE_NAMES { YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank', SUBSCRIBE_ONBOARDING = 'Subscribe onboarding', CREATE_ORTTO_PROFILE = 'Create Ortto profile', + + NOTIFY_REWARD_AMOUNT = 'Notify reward amount', } diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 63da68e..e0b0f86 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -49,6 +49,8 @@ export enum NOTIFICATIONS_EVENT_NAMES { SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', CREATE_ORTTO_PROFILE = 'Create Ortto profile', SEND_EMAIL_CONFIRMATION = 'Send email confirmation', + + NOTIFY_REWARD_AMOUNT = 'Notify reward amount', } export const ORTTO_EVENT_NAMES = { @@ -69,4 +71,5 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning', [NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile', [NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION]: 'verification-form-email-verification', + [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount' } \ No newline at end of file diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index d90c7ad..a4ccd88 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -176,6 +176,18 @@ const sendEmailConfirmationSchema = Joi.object({ verificationLink: Joi.string().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; @@ -349,6 +361,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { metadata: projectTitleProjectLinkSchema, segment: null, }, + notifyRewardAmount: { + metadata: null, + segment: notifyRewardAmountSegmentSchema, + }, }; function throwHttpErrorIfJoiValidatorFails( diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index dee0df5..179f86b 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -92,6 +92,10 @@ export const sendNotificationValidator = Joi.object({ // Project update update: Joi.string(), + + // Notify reward attributes + contractAddress: Joi.string(), + farm: Joi.string(), }), }), });