Skip to content

Commit

Permalink
Merge branch 'refs/heads/staging' into User-Story---Rejected-project-…
Browse files Browse the repository at this point in the history
…owner-reason

# Conflicts:
#	src/validators/schemaValidators.ts
  • Loading branch information
RamRamez committed Jul 1, 2024
2 parents 3b096fd + cfec49d commit 1fda316
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 20 deletions.
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 @@ -172,8 +172,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 @@ -205,9 +209,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 @@ -222,10 +224,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 @@ -167,12 +167,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 @@ -249,10 +258,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(''),

// Verification form
verificationRejectedReason: Joi.string().allow(null, ''),

Expand Down

0 comments on commit 1fda316

Please sign in to comment.