From ddfae671620b3c96c19903aecb9ca91ee0430f24 Mon Sep 17 00:00:00 2001 From: Ramin Date: Wed, 10 Apr 2024 00:25:41 +0330 Subject: [PATCH] add SUPER_TOKENS NOTIFICATIONS_EVENT_NAMES --- src/services/notificationService.ts | 45 ++++++++++++++++++++--------- src/types/notifications.ts | 8 +++-- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index f0517dc..7ff5550 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -24,12 +24,29 @@ const activityCreator = (payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES } let attributes; switch (orttoEventName) { - case NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL: + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_DEPLETED: attributes = { "str:cm:tokensymbol": payload.tokenSymbol, "str:cm:email": payload.email, "str:cm:userId": payload.userId?.toString(), - "str:cm:criticalDate": payload.criticalDate, + "bol:cm:isended": payload.isEnded, + } + break; + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_WEEK: + attributes = { + "str:cm:tokensymbol": payload.tokenSymbol, + "str:cm:email": payload.email, + "str:cm:userId": payload.userId?.toString(), + "str:cm:criticalDate": 'week', + "bol:cm:isended": payload.isEnded, + } + break; + case NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_MONTH: + attributes = { + "str:cm:tokensymbol": payload.tokenSymbol, + "str:cm:email": payload.email, + "str:cm:userId": payload.userId?.toString(), + "str:cm:criticalDate": 'month', "bol:cm:isended": payload.isEnded, } break; @@ -184,6 +201,17 @@ export const sendNotification = async ( userAddressId: userAddress.id, }); + const shouldSendEmail = + body.sendEmail && notificationSetting?.allowEmailNotification; + let emailStatus = shouldSendEmail + ? EMAIL_STATUSES.WAITING_TO_BE_SEND + : EMAIL_STATUSES.NO_NEED_TO_SEND; + + const segmentValidator = + SEGMENT_METADATA_SCHEMA_VALIDATOR[ + notificationType?.schemaValidator as string + ]?.segment; + logger.debug('notificationController.sendNotification()', { notificationSetting, notificationTypeId: notificationType.id, @@ -200,19 +228,10 @@ export const sendNotification = async ( payload: body.segment?.payload, sendEmail: body.sendEmail, sendSegment: body.sendSegment, + segmentValidator, + eventName: body.eventName, }); - const shouldSendEmail = - body.sendEmail && notificationSetting?.allowEmailNotification; - let emailStatus = shouldSendEmail - ? EMAIL_STATUSES.WAITING_TO_BE_SEND - : EMAIL_STATUSES.NO_NEED_TO_SEND; - - const segmentValidator = - SEGMENT_METADATA_SCHEMA_VALIDATOR[ - notificationType?.schemaValidator as string - ]?.segment; - if (shouldSendEmail && body.sendSegment && segmentValidator) { const emailData = body.segment?.payload; validateWithJoiSchema(emailData, segmentValidator); diff --git a/src/types/notifications.ts b/src/types/notifications.ts index 2eeef97..81c253f 100644 --- a/src/types/notifications.ts +++ b/src/types/notifications.ts @@ -1,5 +1,4 @@ export enum NOTIFICATIONS_EVENT_NAMES { - USER_SUPER_TOKENS_CRITICAL = 'Supertokens critical', DRAFTED_PROJECT_ACTIVATED = 'Draft published', PROJECT_LISTED = 'Project listed', PROJECT_UNLISTED = 'Project unlisted', @@ -45,10 +44,15 @@ export enum NOTIFICATIONS_EVENT_NAMES { PROJECT_HAS_RISEN_IN_THE_RANK = 'Your Project has risen in the rank', PROJECT_HAS_A_NEW_RANK = 'Your project has a new rank', YOUR_PROJECT_GOT_A_RANK = 'Your project got a rank', + SUPER_TOKENS_BALANCE_WEEK = 'One week left in stream balance', + SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance', + SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', } export const ORTTO_EVENT_NAMES = { - [NOTIFICATIONS_EVENT_NAMES.USER_SUPER_TOKENS_CRITICAL]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_WEEK]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_MONTH]: 'superfluid-balance-warning', + [NOTIFICATIONS_EVENT_NAMES.SUPER_TOKENS_BALANCE_DEPLETED]: 'superfluid-balance-warning', [NOTIFICATIONS_EVENT_NAMES.DONATION_RECEIVED]: 'testing-donation-received', [NOTIFICATIONS_EVENT_NAMES.DRAFTED_PROJECT_ACTIVATED]: 'project-created', [NOTIFICATIONS_EVENT_NAMES.PROJECT_LISTED]: 'project-listed',