Skip to content

Commit

Permalink
Pull staging and resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Jul 1, 2024
2 parents 347a072 + 9cae75a commit 834cdf3
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 19 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';`,
);
}
}
26 changes: 26 additions & 0 deletions migrations/1719410008992-seedNotificationTypeForOnboardingGuide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { MigrationInterface, QueryRunner } from "typeorm"
import { NotificationType, SCHEMA_VALIDATORS_NAMES } from '../src/entities/notificationType';
import { NOTIFICATION_CATEGORY, NOTIFICATION_TYPE_NAMES } from '../src/types/general';
import { MICRO_SERVICES } from '../src/utils/utils';

const OnboardingNotificationType = [
{
name: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
description: NOTIFICATION_TYPE_NAMES.SUBSCRIBE_ONBOARDING,
microService: MICRO_SERVICES.givethio,
category: NOTIFICATION_CATEGORY.ORTTO,
schemaValidator: SCHEMA_VALIDATORS_NAMES.SUBSCRIBE_ONBOARDING,
}
]

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

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM notification_type WHERE "name" = 'Subscribe onboarding';`,
);
}
}
6 changes: 2 additions & 4 deletions src/entities/notificationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@ 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',
SUBSCRIBE_ONBOARDING: 'subscribeOnboarding',
SUPERFLUID: 'userSuperTokensCritical',
ADMIN_MESSAGE: 'adminMessage',
RAW_HTML_BROADCAST: 'rawHtmlBroadcast',
Expand Down
29 changes: 18 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 @@ -126,6 +126,7 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'rejected',
"txt:cm:reason": payload.verificationRejectedReason,
"str:cm:userid": payload.userId?.toString(),
};
break
Expand Down Expand Up @@ -184,8 +185,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 @@ -217,9 +222,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 @@ -234,10 +237,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
1 change: 1 addition & 0 deletions src/types/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum NOTIFICATION_TYPE_NAMES {
PROJECT_HAS_A_NEW_RANK = 'Your project has a new rank',
PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank',
YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank',
SUBSCRIBE_ONBOARDING = 'Subscribe onboarding',
CREATE_ORTTO_PROFILE = 'Create Ortto profile',

NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
Expand Down
2 changes: 2 additions & 0 deletions 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',

NOTIFY_REWARD_AMOUNT = 'Notify reward amount',
}
Expand All @@ -69,5 +70,6 @@ export const ORTTO_EVENT_NAMES = {
[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.SEND_EMAIL_CONFIRMATION]: 'verification-form-email-verification',
[NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT]: 'notify-reward-amount'
}
22 changes: 18 additions & 4 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const projectRelatedTrackerSchema = Joi.object({
slug: Joi.string().required(),
projectLink: Joi.string().allow(null).allow(''),

verificationRejectedReason: Joi.string().allow(null, ''),
// it's for project updates
update: Joi.string().allow(null, ''),
});
Expand Down Expand Up @@ -159,13 +160,22 @@ const superFluidTokenSegmentSchema = Joi.object({
isEnded: Joi.boolean(),
});

const subscribeOnboardingSchema = Joi.object({
email: Joi.string().required(),
})

const createOrttoProfileSegmentSchema = Joi.object({
email: Joi.string().required(),
firstName: Joi.string().required(),
lastName: Joi.string().required(),
userId: Joi.number().required()
})

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

const notifyRewardAmountSegmentSchema = Joi.object({
round: Joi.number().required(),
date: Joi.string().required(),
Expand All @@ -184,10 +194,18 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: ObjectSchema | null;
};
} = {
sendEmailConfirmation: {
metadata: null,
segment: sendEmailConfirmationSchema,
},
createOrttoProfile: {
segment: createOrttoProfileSegmentSchema,
metadata: null
},
subscribeOnboarding: {
segment: subscribeOnboardingSchema,
metadata: null
},
userSuperTokensCritical: {
metadata: superFluidTokenMetadataSchema,
segment: superFluidTokenSegmentSchema,
Expand Down Expand Up @@ -260,10 +278,6 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
metadata: projectTitleProjectLinkSchema,
segment: null,
},
sendEmailConfirmation: {
metadata: null,
segment: projectRelatedTrackerSchema,
},
madeDonation: {
metadata: projectTitleProjectLinkSchema,
segment: donationTrackerSchema,
Expand Down
6 changes: 6 additions & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ 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, ''),

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

0 comments on commit 834cdf3

Please sign in to comment.