Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add notification types for Qacc #118

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions migrations/1723505340806-addNotificationTypesForQacc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
ae2079 marked this conversation as resolved.
Show resolved Hide resolved
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<void> {
await queryRunner.manager.save('notification_type', QaccNotificationTypes);
}

public async down(queryRunner: QueryRunner): Promise<void> {
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';`,
);
}
}
1 change: 1 addition & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];

Expand Down
10 changes: 10 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
3 changes: 3 additions & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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',
};
1 change: 1 addition & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -352,4 +361,8 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: null,
segment: notifyRewardAmountSegmentSchema,
},
donationReceivedForQacc: {
metadata: null,
segment: donationReceivedForQaccSegmentSchema,
},
};
5 changes: 5 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}),
}),
});
Expand Down
Loading