Skip to content

Commit

Permalink
Merge branch 'staging' into add-badge-revoke-events
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/types/notifications.ts
  • Loading branch information
RamRamez committed Feb 29, 2024
2 parents b925592 + 05a9322 commit 997822e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
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 Down Expand Up @@ -114,6 +122,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 @@ -174,6 +187,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 @@ -188,12 +204,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,6 +56,7 @@ 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',
[NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_WARNING]: 'first-update-warning',
[NOTIFICATIONS_EVENT_NAMES.PROJECT_BADGE_REVOKE_LAST_WARNING]: 'second-update-warning',
}
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
1 change: 1 addition & 0 deletions src/validators/schemaValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const throwHttpErrorIfJoiValidatorFails = (
throw error;
}
};

export const countUnreadValidator = Joi.object({
walletAddress: Joi.alternatives().try(
Joi.string().required().pattern(ethereumWalletAddressRegex),
Expand Down

0 comments on commit 997822e

Please sign in to comment.