diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 1af262d..d1e84b4 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -80,6 +80,14 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES "str:cm:verified-status": 'verified', }; break + case NOTIFICATIONS_EVENT_NAMES.VERIFICATION_FORM_REJECTED: + 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_UNVERIFIED: attributes = { "str:cm:projecttitle": payload.title, @@ -98,6 +106,11 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES break default: logger.debug('activityCreator() invalid event name', orttoEventName) + return; + } + if (!ORTTO_EVENT_NAMES[orttoEventName]) { + logger.debug('activityCreator() invalid ORTTO_EVENT_NAMES', orttoEventName) + return; } return { activities: [ @@ -158,6 +171,9 @@ export const sendNotification = async ( }, trackId: body.trackId, metadata: body.metadata, + payload: body.segment?.payload, + sendEmail: body.sendEmail, + sendSegment: body.sendSegment, }); const shouldSendEmail = @@ -172,12 +188,12 @@ export const sendNotification = async ( ]?.segment; if (shouldSendEmail && body.sendSegment && segmentValidator) { - //TODO Currently sending email and segment event are tightly coupled, we can't send segment event without sending email - // And it's not good, we should find another solution to separate sending segment and email const emailData = body.segment?.payload; validateWithJoiSchema(emailData, segmentValidator); const data = activityCreator(emailData, body.eventName as NOTIFICATIONS_EVENT_NAMES); - await getEmailAdapter().callOrttoActivity(data); + if (data) { + await getEmailAdapter().callOrttoActivity(data); + } emailStatus = EMAIL_STATUSES.SENT; } diff --git a/src/types/notifications.ts b/src/types/notifications.ts index a57883c..19627e6 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -56,4 +56,5 @@ export const ORTTO_EVENT_NAMES = { [NOTIFICATIONS_EVENT_NAMES.PROJECT_UNVERIFIED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_VERIFIED]: 'project-verification', [NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKED]: 'project-verification', + [NOTIFICATIONS_EVENT_NAMES.VERIFICATION_FORM_REJECTED]: 'project-verification', } \ No newline at end of file diff --git a/src/utils/validators/segmentAndMetadataValidators.ts b/src/utils/validators/segmentAndMetadataValidators.ts index 6e63c89..cc3e8ab 100644 --- a/src/utils/validators/segmentAndMetadataValidators.ts +++ b/src/utils/validators/segmentAndMetadataValidators.ts @@ -261,7 +261,7 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: { }, verificationFormRejected: { metadata: projectTitleProjectLinkReasonSchema, - segment: null, + segment: projectRelatedTrackerSchema, }, verificationFormReapplyReminder: { metadata: verificationFormReapplyReminderSchema, diff --git a/src/validators/schemaValidators.ts b/src/validators/schemaValidators.ts index c761f94..3ba478e 100644 --- a/src/validators/schemaValidators.ts +++ b/src/validators/schemaValidators.ts @@ -22,6 +22,7 @@ const throwHttpErrorIfJoiValidatorFails = ( throw error; } }; + export const countUnreadValidator = Joi.object({ walletAddress: Joi.alternatives().try( Joi.string().required().pattern(ethereumWalletAddressRegex),