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

Add userId to all notification center calls #73

Merged
merged 3 commits into from
Feb 21, 2024
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
2 changes: 0 additions & 2 deletions src/adapters/emailAdapter/orttoAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { logger } from '../../utils/logger';
import axios from 'axios';
import {OrttoAdapterInterface} from "./orttoAdapterInterface";


export class OrttoAdapter implements OrttoAdapterInterface{
async callOrttoActivity(data: any): Promise<void> {
try {
Expand All @@ -28,5 +27,4 @@ export class OrttoAdapter implements OrttoAdapterInterface{
});
}
}

}
208 changes: 71 additions & 137 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,164 +16,98 @@ import { NOTIFICATIONS_EVENT_NAMES, ORTTO_EVENT_NAMES } from '../types/notificat
import {getEmailAdapter} from "../adapters/adapterFactory";

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
}
let attributes;
switch (orttoEventName) {
case NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:donationamount": payload.amount.toString(),
"str:cm:donationtoken": payload.token,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"bol:cm:verified": payload.verified,
"str:cm:transactionlink": payload.transactionLink,
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:donationamount": payload.amount.toString(),
"str:cm:donationtoken": payload.token,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"bol:cm:verified": payload.verified,
"str:cm:transactionlink": payload.transactionLink,
};
break
case NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:firstname": payload.firstName,
"str:cm:lastname": payload.lastName,
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:firstname": payload.firstName,
"str:cm:lastname": payload.lastName,
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_LISTED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_UNLISTED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_CANCELLED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_UPDATE_ADDED_OWNER:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectupdatelink": payload.projectLink + '?tab=updates',
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectupdatelink": payload.projectLink + '?tab=updates',
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_VERIFIED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'verified',
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'verified',
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_UNVERIFIED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'rejected',
},
"fields": {
"str::email": payload.email
}
}
]
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'rejected',
};
break
case NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKED:
return {
"activities": [
{
"activity_id": `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
"attributes": {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'revoked',
},
"fields": {
"str::email": payload.email
}
}
]
};
attributes = {
"str:cm:projecttitle": payload.title,
"str:cm:email": payload.email,
"str:cm:projectlink": payload.projectLink,
"str:cm:verified-status": 'revoked',
}
break
default:
logger.debug('activityCreator() invalid event name', orttoEventName)
return undefined
}
return {
activities: [
{
activity_id: `act:cm:${ORTTO_EVENT_NAMES[orttoEventName]}`,
attributes,
fields,
}
]
};
}

export const sendNotification = async (
Expand Down
1 change: 1 addition & 0 deletions src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const projectRelatedTrackerSchema = Joi.object({
title: Joi.string().required(),
firstName: Joi.string().allow(null, ''),
lastName: Joi.string().allow(null, ''),
userId: Joi.string(),
OwnerId: Joi.number(),
slug: Joi.string().required(),
projectLink: Joi.string().allow(null).allow(''),
Expand Down
1 change: 1 addition & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const sendNotificationValidator = Joi.object({
title: Joi.string(),
slug: Joi.string(),
firstName: Joi.string().allow(null).allow(''),
userId: Joi.string(),
projectLink: Joi.string().allow(null).allow(''),

// Donation related attributes
Expand Down
Loading