Skip to content

Commit

Permalink
Merge pull request #76 from Giveth/send-notification-when-VERIFICATIO…
Browse files Browse the repository at this point in the history
…N_FORM_REJECTED

send notification when VERIFICATION_FORM_REJECTED
  • Loading branch information
RamRamez authored Feb 26, 2024
2 parents 46fa351 + 11c5ff8 commit 90734ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/adapters/emailAdapter/orttoAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: [
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/types/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
2 changes: 1 addition & 1 deletion src/utils/validators/segmentAndMetadataValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const SEGMENT_METADATA_SCHEMA_VALIDATOR: {
},
verificationFormRejected: {
metadata: projectTitleProjectLinkReasonSchema,
segment: null,
segment: projectRelatedTrackerSchema,
},
verificationFormReapplyReminder: {
metadata: verificationFormReapplyReminderSchema,
Expand Down

0 comments on commit 90734ad

Please sign in to comment.