Skip to content

Commit

Permalink
feat: create notification to email verification code flow
Browse files Browse the repository at this point in the history
  • Loading branch information
Reshzera committed Aug 14, 2024
1 parent 0a22290 commit be9a06f
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 3 deletions.
34 changes: 34 additions & 0 deletions migrations/1723578137845-addEmailVerificationCodeFlow.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 EmailConfirmationNotificationCodeFlowType = [
{
name: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION_CODE_FLOW,
description: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION_CODE_FLOW,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION_CODE_FLOW,
},
];

export class AddEmailVerificationCodeFlow1723578137845
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.manager.save(
NotificationType,
EmailConfirmationNotificationCodeFlowType,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Send email confirmation code flow';`,
);
}
}
1 change: 1 addition & 0 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_EMAIL_CONFIRMATION_CODE_FLOW: 'sendEmailConfirmationCodeFlow',
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
SUPERFLUID: 'userSuperTokensCritical',
Expand Down
14 changes: 11 additions & 3 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ export const activityCreator = (
'str:cm:verificationlink': payload.verificationLink,
};
break;

case NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION_CODE_FLOW:
attributes = {
'str:cm:email': payload.email,
'int:cm:code': payload.verificationCode,
'str:cm:userid': payload.userId?.toString(),
};
break;
case NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE:
attributes = {
'str:cm:email': payload.email,
Expand Down Expand Up @@ -202,11 +210,11 @@ export const activityCreator = (
logger.debug('activityCreator() invalid event name', orttoEventName);
return;
}
if (!ORTTO_EVENT_NAMES[orttoEventName]) {
if (!ORTTO_EVENT_NAMES[orttoEventName as keyof typeof ORTTO_EVENT_NAMES]) {
logger.debug('activityCreator() invalid ORTTO_EVENT_NAMES', orttoEventName);
return;
}
const fields = {
const fields: Record<string, any> = {
'str::email': payload.email,
};
const merge_by = [];
Expand All @@ -223,7 +231,7 @@ export const activityCreator = (
return {
activities: [
{
activity_id: `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
activity_id: `act:cm:${ORTTO_EVENT_NAMES[orttoEventName as keyof typeof ORTTO_EVENT_NAMES]}`,
attributes,
fields,
},
Expand Down
3 changes: 3 additions & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_EMAIL_CONFIRMATION_CODE_FLOW = 'Send email confirmation code flow',
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
}
Expand Down Expand Up @@ -79,6 +80,8 @@ export const ORTTO_EVENT_NAMES = {
[NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile',
[NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION]:
'verification-form-email-verification',
[NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION_CODE_FLOW]:
'email-verification-code',
[NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward',
[NOTIFICATIONS_EVENT_NAMES.SUBSCRIBE_ONBOARDING]: 'onboarding-form',
};
10 changes: 10 additions & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ const sendEmailConfirmationSchema = Joi.object({
verificationLink: Joi.string().required(),
});

const sendEmailConfirmationCodeFlowSchema = Joi.object({
email: Joi.string().required(),
verificationCode: Joi.number().required(),
userId: Joi.number().required(),
});

const notifyRewardAmountSegmentSchema = Joi.object({
round: Joi.number().required(),
date: Joi.string().required(),
Expand All @@ -185,6 +191,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: null,
segment: sendEmailConfirmationSchema,
},
sendEmailConfirmationCodeFlow: {
metadata: null,
segment: sendEmailConfirmationCodeFlowSchema,
},
createOrttoProfile: {
segment: createOrttoProfileSegmentSchema,
metadata: null,
Expand Down
1 change: 1 addition & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const sendNotificationValidator = Joi.object({
slug: Joi.string(),
firstName: Joi.string().allow(null).allow(''),
userId: Joi.number(),
verificationCode: Joi.number().allow(null).allow(''),
projectLink: Joi.string().allow(null).allow(''),

// Email confirmation
Expand Down

0 comments on commit be9a06f

Please sign in to comment.