Skip to content

Commit

Permalink
fix(api): remove unnecessary logging and improve SupportService initi…
Browse files Browse the repository at this point in the history
…alization
  • Loading branch information
merrcury committed Nov 6, 2024
1 parent b20eb36 commit 984b066
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 25 deletions.
10 changes: 1 addition & 9 deletions apps/api/src/app/support/support.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ export class SupportController {
) {}

@Post('plain/cards')
async getPlainCards(@Body() body: any) {
const userId = body.customer?.externalId;
const { email } = body.customer || {};

console.log('userId', userId);
console.log('email', email);
console.log('body', body);
const userRepo = this.userRepository;

async getPlainCards() {
return {
data: {},

Expand Down
14 changes: 2 additions & 12 deletions libs/application-generic/src/custom-providers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
CacheService,
DistributedLockService,
FeatureFlagsService,
SupportService,
} from '../services';
import { GetFeatureFlag } from '../usecases';

Expand All @@ -22,7 +21,7 @@ export const featureFlagsService = {
export const getFeatureFlag = {
provide: GetFeatureFlag,
useFactory: async (
featureFlagsServiceItem: FeatureFlagsService,
featureFlagsServiceItem: FeatureFlagsService
): Promise<GetFeatureFlag> => {
const useCase = new GetFeatureFlag(featureFlagsServiceItem);

Expand Down Expand Up @@ -79,20 +78,11 @@ export const distributedLockService = {
cacheInMemoryProviderService.useFactory();

const service = new DistributedLockService(
factoryCacheInMemoryProviderService,
factoryCacheInMemoryProviderService
);

await service.initialize();

return service;
},
};

export const supportService = {
provide: SupportService,
useFactory: async () => {
const service = new SupportService();

return service;
},
};
12 changes: 8 additions & 4 deletions libs/application-generic/src/services/support.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ export class SupportService {
private readonly plainKey: string;
constructor() {
this.plainKey = process.env.PLAIN_SUPPORT_KEY;
this.plainClient = new PlainClient({ apiKey: this.plainKey });
Logger.log(`Initialized PlainClient`, LOG_CONTEXT);
if (this.plainKey) {
this.plainClient = new PlainClient({ apiKey: this.plainKey });
Logger.log(`Initialized PlainClient`, LOG_CONTEXT);
} else {
Logger.log('Skipping PlainClient initialization', LOG_CONTEXT);
}
}

async upsertCustomer({ emailAddress, fullName, novuUserId }) {
const res = await this.plainClient.upsertCustomer({
const res = await this.plainClient?.upsertCustomer({
identifier: {
emailAddress,
},
Expand Down Expand Up @@ -49,7 +53,7 @@ export class SupportService {
}

async createThread({ plainCustomerId, threadText }) {
const res = await this.plainClient.createThread({
const res = await this.plainClient?.createThread({
customerIdentifier: {
customerId: plainCustomerId,
},
Expand Down

0 comments on commit 984b066

Please sign in to comment.