diff --git a/migrations/1731590176819-addUserEmailNotification.ts b/migrations/1731590176819-addUserEmailNotification.ts new file mode 100644 index 0000000..cec4190 --- /dev/null +++ b/migrations/1731590176819-addUserEmailNotification.ts @@ -0,0 +1,37 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; +import { + SCHEMA_VALIDATORS_NAMES, + NotificationType, +} from '../src/entities/notificationType'; +import { NOTIFICATION_CATEGORY } from '../src/types/general'; +import { NOTIFICATIONS_EVENT_NAMES } from '../src/types/notifications'; +import { MICRO_SERVICES } from '../src/utils/utils'; + +const UserEmailConfirmationNotificationCodeFlowType = [ + { + name: NOTIFICATIONS_EVENT_NAMES.SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW, + description: + NOTIFICATIONS_EVENT_NAMES.SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW, + microService: MICRO_SERVICES.givethio, + category: NOTIFICATION_CATEGORY.ORTTO, + schemaValidator: + SCHEMA_VALIDATORS_NAMES.SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW, + }, +]; + +export class AddUserEmailNotification1731590176819 + implements MigrationInterface +{ + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.manager.save( + NotificationType, + UserEmailConfirmationNotificationCodeFlowType, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `DELETE FROM notification_type WHERE "name" = 'Send email confirmation code flow';`, + ); + } +} diff --git a/src/entities/notificationType.ts b/src/entities/notificationType.ts index a26fad5..9a70611 100644 --- a/src/entities/notificationType.ts +++ b/src/entities/notificationType.ts @@ -13,6 +13,7 @@ import { NotificationSetting } from './notificationSetting'; // Export Object with Schemas to N1 lookup export const SCHEMA_VALIDATORS_NAMES = { SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation', + SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW: 'sendUserEmailConfirmationCodeFlow', CREATE_ORTTO_PROFILE: 'createOrttoProfile', SUBSCRIBE_ONBOARDING: 'subscribeOnboarding', SUPERFLUID: 'userSuperTokensCritical', diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 2640ed9..85e5edb 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -39,6 +39,13 @@ export const activityCreator = ( 'str:cm:verificationlink': payload.verificationLink, }; break; + case NOTIFICATIONS_EVENT_NAMES.SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW: + attributes = { + 'str:cm:email': payload.email, + 'int:cm:code': Number(payload.verificationCode), + 'str:cm:userid': payload.userId?.toString(), + }; + break; case NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE: attributes = { 'str:cm:email': payload.email, diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 68d1d35..3d22ecc 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -50,6 +50,7 @@ export enum NOTIFICATIONS_EVENT_NAMES { SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', CREATE_ORTTO_PROFILE = 'Create Ortto profile', SEND_EMAIL_CONFIRMATION = 'Send email confirmation', + SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW = 'Send email confirmation code flow', SUBSCRIBE_ONBOARDING = 'Subscribe onboarding', NOTIFY_REWARD_AMOUNT = 'Notify reward amount', } @@ -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.SEND_USER_EMAIL_CONFIRMATION_CODE_FLOW]: + 'email-verification-code', }; diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 915d5bf..145ceb1 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -162,6 +162,12 @@ const sendEmailConfirmationSchema = Joi.object({ verificationLink: Joi.string().required(), }); +const sendUserEmailConfirmationCodeFlowSchema = Joi.object({ + email: Joi.string().required(), + verificationCode: Joi.string().required(), + userId: Joi.number().required(), +}); + const notifyRewardAmountSegmentSchema = Joi.object({ round: Joi.number().required(), date: Joi.string().required(), @@ -185,6 +191,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { metadata: null, segment: sendEmailConfirmationSchema, }, + sendUserEmailConfirmationCodeFlow: { + metadata: null, + segment: sendUserEmailConfirmationCodeFlowSchema, + }, createOrttoProfile: { segment: createOrttoProfileSegmentSchema, metadata: null, diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index ccd99ff..ae7afcd 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -55,6 +55,7 @@ export const sendNotificationValidator = Joi.object({ email: Joi.string().allow(null).allow(''), title: Joi.string(), slug: Joi.string(), + verificationCode: Joi.string().allow(null).allow(''), firstName: Joi.string().allow(null).allow(''), userId: Joi.number(), projectLink: Joi.string().allow(null).allow(''),