From 11c5ff803f60ef7d3bc76181925a86138515fd4d Mon Sep 17 00:00:00 2001 From: Ramin Date: Sun, 25 Feb 2024 20:26:14 +0330 Subject: [PATCH] send notification when VERIFICATION_FORM_REJECTED --- src/adapters/emailAdapter/orttoAdapter.ts | 4 ++-- src/services/notificationService.ts | 22 ++++++++++++++++--- src/types/notifications.ts | 1 + .../segmentAndMetadataValidators.ts | 2 +- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/adapters/emailAdapter/orttoAdapter.ts b/src/adapters/emailAdapter/orttoAdapter.ts index dd4e060..095d720 100644 --- a/src/adapters/emailAdapter/orttoAdapter.ts +++ b/src/adapters/emailAdapter/orttoAdapter.ts @@ -22,8 +22,8 @@ export class OrttoAdapter implements OrttoAdapterInterface{ await axios.request(config); } catch (e) { logger.error('orttoActivityCall error', { - error: JSON.stringify(e), - data: JSON.stringify(data) + error: e, + data }); } } 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,