Skip to content

Commit

Permalink
Merge pull request #73 from Giveth/Add-userId-to-all-notification-cen…
Browse files Browse the repository at this point in the history
…ter-calls

Add userId to all notification center calls
  • Loading branch information
RamRamez authored Feb 21, 2024
2 parents 376fb4b + cf0c8bc commit 70212cb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 139 deletions.
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 @@ -29,5 +28,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

0 comments on commit 70212cb

Please sign in to comment.