Skip to content

Commit

Permalink
support Qacc on Ortto
Browse files Browse the repository at this point in the history
  • Loading branch information
ae2079 committed Aug 20, 2024
1 parent 0a22290 commit ede15cf
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions config/example.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/adapters/emailAdapter/orttoAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import axios from 'axios';

Check failure on line 1 in src/adapters/emailAdapter/orttoAdapter.ts

View workflow job for this annotation

GitHub Actions / test

Property 'qacc' does not exist on type '{ givethio: string; givEconomyNotificationMicroService: string; trace: string; notifyReward: string; }'.
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<void> {
async callOrttoActivity(data: any, microService: string): Promise<void> {
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,
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/emailAdapter/orttoAdapterInterface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface OrttoAdapterInterface {
callOrttoActivity(data: any): Promise<void>;
callOrttoActivity(data: any, microService: string): Promise<void>;
}
4 changes: 2 additions & 2 deletions src/adapters/emailAdapter/orttoMockAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logger } from '../../utils/logger';
import { OrttoAdapterInterface } from './orttoAdapterInterface';

export class OrttoMockAdapter implements OrttoAdapterInterface {
async callOrttoActivity(data: any): Promise<void> {
logger.debug('OrttoMockAdapter has been called', data);
async callOrttoActivity(data: any, microService: string): Promise<void> {
logger.debug('OrttoMockAdapter has been called', data, microService);
}
}
2 changes: 2 additions & 0 deletions src/services/notificationService.test.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand All @@ -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({
Expand Down
8 changes: 6 additions & 2 deletions src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ede15cf

Please sign in to comment.