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

support Qacc on Ortto #119

Merged
merged 2 commits into from
Aug 20, 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
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';
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
1 change: 1 addition & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading