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

sending email for notify reward amount #99

Merged
merged 5 commits into from
Jul 2, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -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,
Copy link
Contributor Author

@ae2079 ae2079 Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohammadranjbarz
I ran the migration and these fields are set successfully, but I am not sure about the correctness of their values and I don't know if I should put other fields too, or not

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<void> {
await queryRunner.manager.save(NotificationType, NotifyRewardAmountNotificationType);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = ${NOTIFICATION_TYPE_NAMES.NOTIFY_REWARD_AMOUNT};`,
);
}
}
2 changes: 2 additions & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }[];

Expand Down
13 changes: 13 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
ae2079 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
5 changes: 4 additions & 1 deletion src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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',
}
3 changes: 3 additions & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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'
}
16 changes: 16 additions & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -349,6 +361,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: projectTitleProjectLinkSchema,
segment: null,
},
notifyRewardAmount: {
metadata: null,
segment: notifyRewardAmountSegmentSchema,
},
};

function throwHttpErrorIfJoiValidatorFails(
Expand Down
4 changes: 4 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ export const sendNotificationValidator = Joi.object({

// Project update
update: Joi.string(),

// Notify reward attributes
contractAddress: Joi.string(),
farm: Joi.string(),
}),
}),
});
Expand Down
Loading