Skip to content

Commit

Permalink
Merge pull request #99 from Giveth/4194-sending-email-for-givpower
Browse files Browse the repository at this point in the history
sending email for notify reward amount
  • Loading branch information
mohammadranjbarz authored Jul 2, 2024
2 parents 9cae75a + 834cdf3 commit 8087902
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
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,
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;
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

0 comments on commit 8087902

Please sign in to comment.