From a40a0e1c1649649227b3bc0f90f189bdb73a663c Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 1 May 2024 23:43:52 +0330 Subject: [PATCH 1/6] add migration for CREATE_ORTTO_PROFILE notification --- ...-seedNotificationTypeForCreateOrttoUser.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 migrations/1714582062587-seedNotificationTypeForCreateOrttoUser.ts diff --git a/migrations/1714582062587-seedNotificationTypeForCreateOrttoUser.ts b/migrations/1714582062587-seedNotificationTypeForCreateOrttoUser.ts new file mode 100644 index 0000000..82ce144 --- /dev/null +++ b/migrations/1714582062587-seedNotificationTypeForCreateOrttoUser.ts @@ -0,0 +1,26 @@ +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 OrttoUserNotificationType = [ + { + name: NOTIFICATION_TYPE_NAMES.CREATE_ORTTO_PROFILE, + description: NOTIFICATION_TYPE_NAMES.CREATE_ORTTO_PROFILE, + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.ORTTO, + schemaValidator: SCHEMA_VALIDATORS_NAMES.CREATE_ORTTO_PROFILE, + } +] + +export class seedNotificationTypeForCreateOrttoUser1714582062587 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.manager.save(NotificationType, OrttoUserNotificationType); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "name" = 'Create Ortto profile';`, + ); + } +} From e6ec3d4bb8908ad6b4971960eef4edef85889ed1 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 1 May 2024 23:44:17 +0330 Subject: [PATCH 2/6] add new NOTIFICATION_CATEGORY --- src/types/general.ts | 2 ++ src/utils/errorMessages.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/src/types/general.ts b/src/types/general.ts index 0489630..62516a5 100644 --- a/src/types/general.ts +++ b/src/types/general.ts @@ -11,6 +11,7 @@ export enum NOTIFICATION_CATEGORY { GIV_ECONOMY = 'givEconomy', SUPPORTED_PROJECTS = 'supportedProjects', GIV_POWER = 'givPower', + ORTTO = 'ortto' } export enum NOTIFICATION_TYPE_NAMES { @@ -50,4 +51,5 @@ export enum NOTIFICATION_TYPE_NAMES { PROJECT_HAS_A_NEW_RANK = 'Your project has a new rank', PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank', YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank', + CREATE_ORTTO_PROFILE = 'Create Ortto profile', } diff --git a/src/utils/errorMessages.ts b/src/utils/errorMessages.ts index 07ed457..156a08c 100644 --- a/src/utils/errorMessages.ts +++ b/src/utils/errorMessages.ts @@ -183,4 +183,5 @@ export const errorMessages = { 'You are not the owner of social profile', ERROR_IN_GETTING_ACCESS_TOKEN_BY_AUTHORIZATION_CODE: 'Error in getting accessToken by authorization code', + ORTTO_SPECIFIC: 'Ortto specific notification' }; From 08127b8550c5db34adcbb50a69b20de1bddf15d9 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 1 May 2024 23:47:12 +0330 Subject: [PATCH 3/6] add CREATE_ORTTO_PROFILE activity --- src/services/notificationService.ts | 39 +++++++++++++++++++++++------ src/types/notifications.ts | 2 ++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 1c2cded..436ea6c 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -1,7 +1,4 @@ -import { - createNotification, - findNotificationByTrackId, -} from '../repositories/notificationRepository'; +import { createNotification, findNotificationByTrackId } from '../repositories/notificationRepository'; import { errorMessages } from '../utils/errorMessages'; import { createNewUserAddressIfNotExists } from '../repositories/userAddressRepository'; import { getNotificationTypeByEventNameAndMicroservice } from '../repositories/notificationTypeRepository'; @@ -13,7 +10,8 @@ import { validateWithJoiSchema } from '../validators/schemaValidators'; import { SendNotificationRequest } from '../types/requestResponses'; import { StandardError } from '../types/StandardError'; import { NOTIFICATIONS_EVENT_NAMES, ORTTO_EVENT_NAMES } from '../types/notifications'; -import {getEmailAdapter} from "../adapters/adapterFactory"; +import { getEmailAdapter } from '../adapters/adapterFactory'; +import { NOTIFICATION_CATEGORY } from '../types/general'; const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES) : any=> { const fields = { @@ -24,6 +22,14 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES } let attributes; switch (orttoEventName) { + case NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE: + attributes = { + "str:cm:email": payload.email, + "str:cm:firstname": payload.firstName, + "str:cm:lastname": payload.lastName, + "str:cm:userid": payload.userId?.toString(), + } + break; case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_DEPLETED: attributes = { "str:cm:tokensymbol": payload.tokenSymbol, @@ -155,6 +161,12 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES logger.debug('activityCreator() invalid ORTTO_EVENT_NAMES', orttoEventName) return; } + const merge_by = []; + if (process.env.ENVIRONMENT === 'production') { + merge_by.push("str:cm:userid") + } else { + merge_by.push("str::email") + } return { activities: [ { @@ -162,7 +174,8 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES attributes, fields, } - ] + ], + merge_by }; } @@ -195,7 +208,10 @@ export const sendNotification = async ( httpStatusCode: 400, }); } - const notificationSetting = + + const isOrttoSpecific = notificationType.category === NOTIFICATION_CATEGORY.ORTTO + + const notificationSetting = isOrttoSpecific ? null : await findNotificationSettingByNotificationTypeAndUserAddress({ notificationTypeId: notificationType.id, userAddressId: userAddress.id, @@ -232,7 +248,7 @@ export const sendNotification = async ( eventName: body.eventName, }); - if (shouldSendEmail && body.sendSegment && segmentValidator) { + if (((shouldSendEmail && body.sendSegment) || isOrttoSpecific) && segmentValidator) { const emailData = body.segment?.payload; validateWithJoiSchema(emailData, segmentValidator); const data = activityCreator(emailData, body.eventName as NOTIFICATIONS_EVENT_NAMES); @@ -242,6 +258,13 @@ export const sendNotification = async ( emailStatus = EMAIL_STATUSES.SENT; } + if (isOrttoSpecific) { + return { + success: true, + message: errorMessages.ORTTO_SPECIFIC, + } + } + const metadataValidator = SEGMENT_METADATA_SCHEMA_VALIDATOR[ notificationType?.schemaValidator as string diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 81c253f..b7c85bd 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -47,6 +47,7 @@ export enum NOTIFICATIONS_EVENT_NAMES { SUPER_TOKENS_BALANCE_WEEK = 'One week left in stream balance', SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance', SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', + CREATE_ORTTO_PROFILE = 'Create Ortto profile', } export const ORTTO_EVENT_NAMES = { @@ -65,4 +66,5 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.VERIFICATION_FORM_REJECTED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING]: 'first-update-warning', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning', + [NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile' } \ No newline at end of file From 701439a984cdf5a9a7021651661888e5cd26a630 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 1 May 2024 23:48:15 +0330 Subject: [PATCH 4/6] add createOrttoProfile SCHEMA VALIDATORS --- src/entities/notificationType.ts | 1 + src/utils/validators/segmentAndMetadataValidators.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index a4077b9..888600d 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -16,6 +16,7 @@ import { NotificationSetting } from './notificationSetting'; // Export Object with Schemas to N1 lookup export const SCHEMA_VALIDATORS_NAMES = { + CREATE_ORTTO_PROFILE: 'createOrttoProfile', SUPERFLUID: 'userSuperTokensCritical', ADMIN_MESSAGE: 'adminMessage', RAW_HTML_BROADCAST: 'rawHtmlBroadcast', diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index d943134..4931ff6 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -160,12 +160,23 @@ const superFluidTokenSegmentSchema = Joi.object({ isEnded: Joi.boolean(), }); +const createOrttoProfileSegmentSchema = Joi.object({ + email: Joi.string().required(), + firstName: Joi.string().required(), + lastName: Joi.string().required(), + userId: Joi.number().required() +}) + export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { [key: string]: { segment: ObjectSchema | null; metadata: ObjectSchema | null; }; } = { + createOrttoProfile: { + segment: createOrttoProfileSegmentSchema, + metadata: null + }, userSuperTokensCritical: { metadata: superFluidTokenMetadataSchema, segment: superFluidTokenSegmentSchema, From e7c85c877694c37541cab466ea81c5141c0b1290 Mon Sep 17 00:00:00 2001 From: Ramin Date: Thu, 9 May 2024 02:05:20 +0330 Subject: [PATCH 5/6] remove projectOwnerId --- src/routes/v1/notificationRouter.test.ts | 4 ---- src/utils/validators/segmentAndMetadataValidators.ts | 1 - src/validators/schemaValidators.ts | 1 - 3 files changed, 6 deletions(-) diff --git a/src/routes/v1/notificationRouter.test.ts b/src/routes/v1/notificationRouter.test.ts index 5d8021d..387c745 100644 --- a/src/routes/v1/notificationRouter.test.ts +++ b/src/routes/v1/notificationRouter.test.ts @@ -1387,7 +1387,6 @@ function sendNotificationTestCases() { email: 'test@giveth.com', title: 'How many photos is too many photos?', firstName: 'firstName', - projectOwnerId: '68', slug: 'how-many-photos-is-too-many-photos', amount: 0.0001, transactionId: generateRandomTxHash(), @@ -1428,7 +1427,6 @@ function sendNotificationTestCases() { email: 'test@giveth.com', title: 'How many photos is too many photos?', firstName: 'firstName', - projectOwnerId: '68', slug: 'how-many-photos-is-too-many-photos', amount: 0.0001, transactionId: generateRandomTxHash(), @@ -1497,7 +1495,6 @@ function sendNotificationTestCases() { email: 'test@giveth.com', title: 'How many photos is too many photos?', firstName: 'firstName', - projectOwnerId: '68', slug: 'how-many-photos-is-too-many-photos', amount: 0.0001, transactionId: generateRandomTxHash(), @@ -1538,7 +1535,6 @@ function sendNotificationTestCases() { email: 'test@giveth.com', title: 'How many photos is too many photos?', firstName: 'firstName', - projectOwnerId: '68', slug: 'how-many-photos-is-too-many-photos', amount: 0.0001, transactionId: generateRandomTxHash(), diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 4931ff6..c932ca1 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -67,7 +67,6 @@ const donationTrackerSchema = Joi.object({ firstName: Joi.string().allow(null, ''), lastName: Joi.string().allow(null, ''), userId: Joi.number(), - projectOwnerId: Joi.string().allow(null, ''), slug: Joi.string().allow(null, ''), projectLink: Joi.string().allow(null, ''), amount: Joi.number()?.greater(0).required(), diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 1eb9aab..7540433 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -61,7 +61,6 @@ export const sendNotificationValidator = Joi.object({ projectLink: Joi.string().allow(null).allow(''), // Donation related attributes - projectOwnerId: Joi.string(), amount: Joi.number(), token: Joi.string().allow(null, ''), transactionId: Joi.string(), From 2562296d1a029f30f764851f9fc908dc132a6144 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 21 May 2024 11:37:55 +0330 Subject: [PATCH 6/6] update version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f591da..f62701e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "notification-venter", - "version": "2.1.0", + "version": "2.2.0", "description": "", "main": "index.js", "scripts": {