Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send notification when VERIFICATION_FORM_REJECTED #76

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading