diff --git a/migrations/1723505340806-addNotificationTypesForQacc.ts b/migrations/1723505340806-addNotificationTypesForQacc.ts new file mode 100644 index 0000000..5de67d8 --- /dev/null +++ b/migrations/1723505340806-addNotificationTypesForQacc.ts @@ -0,0 +1,32 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import { + NOTIFICATION_CATEGORY, + NOTIFICATION_TYPE_NAMES, +} from '../src/types/general'; +import { SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType'; +import { MICRO_SERVICES } from '../src/utils/utils'; + +const QaccNotificationTypes = [ + { + name: NOTIFICATION_TYPE_NAMES.DONATION_RECEIVED_FOR_QACC, + description: 'Project has received a donation', + microService: MICRO_SERVICES.qacc, + category: NOTIFICATION_CATEGORY.ORTTO, + schemaValidator: SCHEMA_VALIDATORS_NAMES.DONATION_RECEIVED_FOR_QACC, + }, +]; + +export class AddNotificationTypesForQacc1723505340806 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.manager.save('notification_type', QaccNotificationTypes); + } + + public async down(queryRunner: QueryRunner): Promise { + const names = QaccNotificationTypes.map(nt => nt.name); + await queryRunner.query( + `DELETE FROM notification_type WHERE name IN (${names.map(name => `'${name}'`).join(', ')}) AND "microService" = 'qacc';`, + ); + } +} diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index a26fad5..1777ee8 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -68,6 +68,7 @@ export const SCHEMA_VALIDATORS_NAMES = { YOUR_PROJECT_GOT_A_RANK: 'yourProjectGotARank', NOTIFY_REWARD_AMOUNT: 'notifyRewardAmount', + DONATION_RECEIVED_FOR_QACC: 'donationReceivedForQacc', }; export type HtmlTemplate = { type: string; content: string; href?: string }[]; diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 1ed4a0f..adbb576 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -198,6 +198,16 @@ export const activityCreator = ( 'str:cm:transactionhash': payload.transactionHash, }; break; + case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED_FOR_QACC: + attributes = { + 'str:cm:donationamount': payload.donationAmount, + 'str:cm:donationtoken': payload.donationToken, + 'str:cm:email': payload.email, + 'str:cm:projectlink': payload.projectLink, + 'str:cm:projecttitle': payload.projectTitle, + 'str:cm:transactionlink': payload.transactionLink, + }; + break; default: logger.debug('activityCreator() invalid event name', orttoEventName); return; diff --git a/src/types/general.ts b/src/types/general.ts index c0e3059..2a15e92 100644 --- a/src/types/general.ts +++ b/src/types/general.ts @@ -55,4 +55,5 @@ export enum NOTIFICATION_TYPE_NAMES { CREATE_ORTTO_PROFILE = 'Create Ortto profile', NOTIFY_REWARD_AMOUNT = 'Notify reward amount', + DONATION_RECEIVED_FOR_QACC = 'Donation received for qacc', } diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 68d1d35..776d589 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -52,6 +52,7 @@ export enum NOTIFICATIONS_EVENT_NAMES { SEND_EMAIL_CONFIRMATION = 'Send email confirmation', SUBSCRIBE_ONBOARDING = 'Subscribe onboarding', NOTIFY_REWARD_AMOUNT = 'Notify reward amount', + DONATION_RECEIVED_FOR_QACC = 'Donation received for qacc', } export const ORTTO_EVENT_NAMES = { @@ -81,4 +82,6 @@ export const ORTTO_EVENT_NAMES = { 'verification-form-email-verification', [NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward', [NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING]: 'onboarding-form', + [NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED_FOR_QACC]: + 'qacc-donation-received', }; diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1d8c328..37d585d 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -20,6 +20,7 @@ export const MICRO_SERVICES = { givEconomyNotificationMicroService: 'giveconomy-notification-service', trace: 'trace', notifyReward: 'notifyreward', + qacc: 'qacc', }; // Need to define trace, blockchain and miscellaneos events diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 915d5bf..09ff529 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -175,6 +175,15 @@ const notifyRewardAmountSegmentSchema = Joi.object({ email: Joi.string().required(), }); +const donationReceivedForQaccSegmentSchema = Joi.object({ + email: Joi.string().required(), + donationAmount: Joi.string().required(), + donationToken: Joi.string().required(), + projectLink: Joi.string().required(), + projectTitle: Joi.string().required(), + transactionLink: Joi.string().required(), +}); + export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { [key: string]: { segment: ObjectSchema | null; @@ -352,4 +361,8 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { metadata: null, segment: notifyRewardAmountSegmentSchema, }, + donationReceivedForQacc: { + metadata: null, + segment: donationReceivedForQaccSegmentSchema, + }, }; diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index ccd99ff..1853e7b 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -101,6 +101,11 @@ export const sendNotificationValidator = Joi.object({ network: Joi.string(), script: Joi.string(), transactionHash: Joi.string(), + + // Qacc donation received + donationAmount: Joi.string(), + donationToken: Joi.string(), + projectTitle: Joi.string(), }), }), });