From ede15cf217041080371349afe306fa14a0f09b93 Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Tue, 20 Aug 2024 05:13:52 +0330 Subject: [PATCH 1/2] support Qacc on Ortto --- config/example.env | 1 + src/adapters/emailAdapter/orttoAdapter.ts | 9 +++++++-- src/adapters/emailAdapter/orttoAdapterInterface.ts | 2 +- src/adapters/emailAdapter/orttoMockAdapter.ts | 4 ++-- src/services/notificationService.test.ts | 2 ++ src/services/notificationService.ts | 8 ++++++-- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/config/example.env b/config/example.env index 59c489c..e1f0859 100644 --- a/config/example.env +++ b/config/example.env @@ -14,6 +14,7 @@ REDIS_PASSWORD= SEGMENT_API_KEY=FAKE_API_KEY ORTTO_API_KEY=FAKE_API_KEY +QACC_ORTTO_API_KEY=FAKE_API_KEY ORTTO_ACTIVITY_API=https://api-us.ortto.app/v1/activities/create #JWT_AUTHORIZATION_ADAPTER=siweMicroservice diff --git a/src/adapters/emailAdapter/orttoAdapter.ts b/src/adapters/emailAdapter/orttoAdapter.ts index a5a0630..07968cb 100644 --- a/src/adapters/emailAdapter/orttoAdapter.ts +++ b/src/adapters/emailAdapter/orttoAdapter.ts @@ -1,19 +1,24 @@ import axios from 'axios'; import { logger } from '../../utils/logger'; import { OrttoAdapterInterface } from './orttoAdapterInterface'; +import { MICRO_SERVICES } from '../../utils/utils'; export class OrttoAdapter implements OrttoAdapterInterface { - async callOrttoActivity(data: any): Promise { + async callOrttoActivity(data: any, microService: string): Promise { try { if (!data) { throw new Error('callOrttoActivity input data is empty'); } + const apiKey = + microService === MICRO_SERVICES.qacc + ? process.env.QACC_ORTTO_API_KEY + : process.env.ORTTO_API_KEY; const config = { method: 'post', maxBodyLength: Infinity, url: process.env.ORTTO_ACTIVITY_API, headers: { - 'X-Api-Key': process.env.ORTTO_API_KEY as string, + 'X-Api-Key': apiKey as string, 'Content-Type': 'application/json', }, data, diff --git a/src/adapters/emailAdapter/orttoAdapterInterface.ts b/src/adapters/emailAdapter/orttoAdapterInterface.ts index 3526e00..3290e46 100644 --- a/src/adapters/emailAdapter/orttoAdapterInterface.ts +++ b/src/adapters/emailAdapter/orttoAdapterInterface.ts @@ -1,3 +1,3 @@ export interface OrttoAdapterInterface { - callOrttoActivity(data: any): Promise; + callOrttoActivity(data: any, microService: string): Promise; } diff --git a/src/adapters/emailAdapter/orttoMockAdapter.ts b/src/adapters/emailAdapter/orttoMockAdapter.ts index d648328..087ec3c 100644 --- a/src/adapters/emailAdapter/orttoMockAdapter.ts +++ b/src/adapters/emailAdapter/orttoMockAdapter.ts @@ -2,7 +2,7 @@ import { logger } from '../../utils/logger'; import { OrttoAdapterInterface } from './orttoAdapterInterface'; export class OrttoMockAdapter implements OrttoAdapterInterface { - async callOrttoActivity(data: any): Promise { - logger.debug('OrttoMockAdapter has been called', data); + async callOrttoActivity(data: any, microService: string): Promise { + logger.debug('OrttoMockAdapter has been called', data, microService); } } diff --git a/src/services/notificationService.test.ts b/src/services/notificationService.test.ts index 01c0f75..a054d6c 100644 --- a/src/services/notificationService.test.ts +++ b/src/services/notificationService.test.ts @@ -1,6 +1,7 @@ import { expect } from 'chai'; import { activityCreator } from './notificationService'; import { NOTIFICATIONS_EVENT_NAMES } from '../types/notifications'; +import { MICRO_SERVICES } from '../utils/utils'; describe('activityCreator', () => { it('should create attributes for NOTIFY_REWARD_AMOUNT', () => { @@ -19,6 +20,7 @@ describe('activityCreator', () => { const result = activityCreator( payload, NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT, + MICRO_SERVICES.givethio, ); expect(JSON.stringify(result)).equal( JSON.stringify({ diff --git a/src/services/notificationService.ts b/src/services/notificationService.ts index 1ed4a0f..2640ed9 100644 --- a/src/services/notificationService.ts +++ b/src/services/notificationService.ts @@ -18,10 +18,12 @@ import { } from '../types/notifications'; import { getEmailAdapter } from '../adapters/adapterFactory'; import { NOTIFICATION_CATEGORY } from '../types/general'; +import { MICRO_SERVICES } from '../utils/utils'; export const activityCreator = ( payload: any, orttoEventName: NOTIFICATIONS_EVENT_NAMES, + microService: string, ): any => { let attributes; let date; @@ -213,7 +215,8 @@ export const activityCreator = ( if ( process.env.ENVIRONMENT === 'production' && orttoEventName !== NOTIFICATIONS_EVENT_NAMES.SEND_EMAIL_CONFIRMATION && - orttoEventName !== NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT + orttoEventName !== NOTIFICATIONS_EVENT_NAMES.NOTIFY_REWARD_AMOUNT && + microService !== MICRO_SERVICES.qacc ) { fields['str:cm:user-id'] = payload.userId?.toString(); merge_by.push('str:cm:user-id'); @@ -314,9 +317,10 @@ export const sendNotification = async ( const data = activityCreator( emailData, body.eventName as NOTIFICATIONS_EVENT_NAMES, + microService, ); if (data) { - await getEmailAdapter().callOrttoActivity(data); + await getEmailAdapter().callOrttoActivity(data, microService); } emailStatus = EMAIL_STATUSES.SENT; } From 9ba94253590bc439f6c6eae1ad9d8855f956ba9f Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Tue, 20 Aug 2024 05:18:32 +0330 Subject: [PATCH 2/2] Add Qacc to microServices --- src/utils/utils.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/utils.ts b/src/utils/utils.ts index 1d8c328..37d585d 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -20,6 +20,7 @@ export const MICRO_SERVICES = { givEconomyNotificationMicroService: 'giveconomy-notification-service', trace: 'trace', notifyReward: 'notifyreward', + qacc: 'qacc', }; // Need to define trace, blockchain and miscellaneos events