diff --git a/src/adapters/emailAdapter/orttoAdapter.ts b/src/adapters/emailAdapter/orttoAdapter.ts index 3ce533d..095d720 100644 --- a/src/adapters/emailAdapter/orttoAdapter.ts +++ b/src/adapters/emailAdapter/orttoAdapter.ts @@ -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 { try { @@ -28,5 +27,4 @@ export class OrttoAdapter implements OrttoAdapterInterface{ }); } } - } diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index ce15ceb..b4f6a67 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -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 ( diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 6c77068..a0dba4c 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -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(''), diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index 7ab5168..9ffb533 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -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