Skip to content

Commit

Permalink
Merge pull request #124 from Giveth/enable_user_email_verification
Browse files Browse the repository at this point in the history
Feat/User mail verification notification
  • Loading branch information
kkatusic authored Nov 22, 2024
2 parents b452f6b + a69f240 commit 3eada61
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
37 changes: 37 additions & 0 deletions migrations/1731590176819-addUserEmailNotification.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
await queryRunner.manager.save(
NotificationType,
UserEmailConfirmationNotificationCodeFlowType,
);
}

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_USER_EMAIL_CONFIRMATION_CODE_FLOW: 'sendUserEmailConfirmationCodeFlow',
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
SUPERFLUID: 'userSuperTokensCritical',
Expand Down
7 changes: 7 additions & 0 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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_USER_EMAIL_CONFIRMATION_CODE_FLOW = 'Send email confirmation code flow',
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
}
Expand Down Expand Up @@ -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',
};
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 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(),
Expand All @@ -185,6 +191,10 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: null,
segment: sendEmailConfirmationSchema,
},
sendUserEmailConfirmationCodeFlow: {
metadata: null,
segment: sendUserEmailConfirmationCodeFlowSchema,
},
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 @@ -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(''),
Expand Down

0 comments on commit 3eada61

Please sign in to comment.