Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do email verification on project verification form through Ortto #101

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NOTIFICATION_CATEGORY } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATIONS_EVENT_NAMES } from '../src/types/notifications';

const EmailConfirmationNotificationType = [
{
name: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
description: NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SEND_EMAIL_CONFIRMATION,
}
]

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

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Send email confirmation';`,
);
}
}
5 changes: 1 addition & 4 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@ import {
CreateDateColumn,
Entity,
Index,
JoinTable,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
RelationId,
UpdateDateColumn,
} from 'typeorm';
import { NOTIFICATION_CATEGORY } from '../types/general';
import { NotificationSetting } from './notificationSetting';

// Export Object with Schemas to N1 lookup
export const SCHEMA_VALIDATORS_NAMES = {
SEND_EMAIL_CONFIRMATION: 'sendEmailConfirmation',
CREATE_ORTTO_PROFILE: 'createOrttoProfile',
SUPERFLUID: 'userSuperTokensCritical',
ADMIN_MESSAGE: 'adminMessage',
Expand Down
28 changes: 17 additions & 11 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { getEmailAdapter } from '../adapters/adapterFactory';
import { NOTIFICATION_CATEGORY } from '../types/general';

const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES) : any=> {
const fields = {
"str::email": payload.email,
}
if (process.env.ENVIRONMENT === 'production') {
fields['str:cm:user-id'] = payload.userId?.toString()
}
let attributes;
switch (orttoEventName) {
case NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION:
attributes = {
"str:cm:email": payload.email,
"str:cm:verificationlink": payload.verificationLink,
}
break;
case NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE:
attributes = {
"str:cm:email": payload.email,
Expand Down Expand Up @@ -171,8 +171,12 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
logger.debug('activityCreator() invalid ORTTO_EVENT_NAMES', orttoEventName)
return;
}
const fields = {
"str::email": payload.email,
}
const merge_by = [];
if (process.env.ENVIRONMENT === 'production') {
if (process.env.ENVIRONMENT === 'production' && orttoEventName !== NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION) {
fields['str:cm:user-id'] = payload.userId?.toString()
merge_by.push("str:cm:user-id")
} else {
merge_by.push("str::email")
Expand Down Expand Up @@ -204,9 +208,7 @@ export const sendNotification = async (
message: errorMessages.DUPLICATED_TRACK_ID,
};
}
const userAddress = await createNewUserAddressIfNotExists(
userWalletAddress as string,
);

const notificationType = await getNotificationTypeByEventNameAndMicroservice({
eventName: body.eventName,
microService,
Expand All @@ -221,10 +223,14 @@ export const sendNotification = async (

const isOrttoSpecific = notificationType.category === NOTIFICATION_CATEGORY.ORTTO

const userAddress = isOrttoSpecific ? undefined : await createNewUserAddressIfNotExists(
userWalletAddress as string,
);

const notificationSetting = isOrttoSpecific ? null :
await findNotificationSettingByNotificationTypeAndUserAddress({
notificationTypeId: notificationType.id,
userAddressId: userAddress.id,
userAddressId: userAddress?.id as number
});

const shouldSendEmail =
Expand Down
4 changes: 3 additions & 1 deletion src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export enum NOTIFICATIONS_EVENT_NAMES {
SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance',
SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',
SEND_EMAIL_CONFIRMATION = 'Send email confirmation',
}

export const ORTTO_EVENT_NAMES = {
Expand All @@ -66,5 +67,6 @@ 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'
[NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE]: 'created-profile',
[NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION]: 'verification-form-email-verification',
}
13 changes: 9 additions & 4 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,21 @@ const createOrttoProfileSegmentSchema = Joi.object({
userId: Joi.number().required()
})

const sendEmailConfirmationSchema = Joi.object({
email: Joi.string().required(),
verificationLink: Joi.string().required(),
});

export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
[key: string]: {
segment: ObjectSchema | null;
metadata: ObjectSchema | null;
};
} = {
sendEmailConfirmation: {
metadata: null,
segment: sendEmailConfirmationSchema,
},
createOrttoProfile: {
segment: createOrttoProfileSegmentSchema,
metadata: null
Expand Down Expand Up @@ -248,10 +257,6 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: projectTitleProjectLinkSchema,
segment: null,
},
sendEmailConfirmation: {
metadata: null,
segment: projectRelatedTrackerSchema,
},
madeDonation: {
metadata: projectTitleProjectLinkSchema,
segment: donationTrackerSchema,
Expand Down
3 changes: 3 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ export const sendNotificationValidator = Joi.object({
userId: Joi.number(),
projectLink: Joi.string().allow(null).allow(''),

// Email confirmation
verificationLink: Joi.string().allow(null).allow(''),

// Donation related attributes
amount: Joi.number(),
token: Joi.string().allow(null, ''),
Expand Down
Loading