Skip to content

Commit

Permalink
✏️ Fix sentry typo import
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jun 18, 2024
1 parent b6809f4 commit 2312f42
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Module } from '@nestjs/common';
import { CrmConnectionsService } from './services/crm.connection.service';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
import { WebhookService } from '@@core/webhook/webhook.service';
import { WebhookModule } from '@@core/webhook/webhook.module';
Expand All @@ -17,6 +16,10 @@ import { CloseConnectionService } from './services/close/close.service';
import { CapsuleConnectionService } from './services/capsule/capsule.service';
import { TeamleaderConnectionService } from './services/teamleader/teamleader.service';
import { ConnectionUtils } from '../@utils';
import { AffinityConnectionService } from './services/affinity/affinity.service';
import { KeapConnectionService } from './services/keap/keap.service';
import { CopperConnectionService } from './services/copper/copper.service';
import { TeamworkConnectionService } from './services/teamwork/teamwork.service';

@Module({
imports: [WebhookModule],
Expand All @@ -38,6 +41,10 @@ import { ConnectionUtils } from '../@utils';
CloseConnectionService,
CapsuleConnectionService,
TeamleaderConnectionService,
AffinityConnectionService,
KeapConnectionService,
CopperConnectionService,
TeamworkConnectionService,
],
exports: [CrmConnectionsService],
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '@@core/prisma/prisma.service';
import { LoggerService } from '@@core/logger/logger.service';
import { v4 as uuidv4 } from 'uuid';
import { EncryptionService } from '@@core/encryption/encryption.service';
import { ICrmConnectionService } from '../../types';
import { ServiceRegistry } from '../registry.service';
import { CONNECTORS_METADATA } from '@panora/shared';
import { ConnectionUtils } from '@@core/connections/@utils';
import { APIKeyCallbackParams } from '@@core/connections/@utils/types';

@Injectable()
export class AffinityConnectionService implements ICrmConnectionService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(AffinityConnectionService.name);
this.registry.registerService('affinity', this);
}

async handleCallback(opts: APIKeyCallbackParams) {
try {
const { linkedUserId, projectId } = opts;
const isNotUnique = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'affinity',
vertical: 'crm',
},
});

let db_res;
const connection_token = uuidv4();

if (isNotUnique) {
db_res = await this.prisma.connections.update({
where: {
id_connection: isNotUnique.id_connection,
},
data: {
access_token: this.cryptoService.encrypt(opts.apikey),
account_url: CONNECTORS_METADATA['crm']['affinity'].urls.apiUrl,
status: 'valid',
created_at: new Date(),
},
});
} else {
db_res = await this.prisma.connections.create({
data: {
id_connection: uuidv4(),
connection_token: connection_token,
provider_slug: 'affinity',
vertical: 'crm',
token_type: 'api_key',
account_url: CONNECTORS_METADATA['crm']['affinity'].urls.apiUrl,
access_token: this.cryptoService.encrypt(opts.apikey),
status: 'valid',
created_at: new Date(),
projects: {
connect: { id_project: projectId },
},
linked_users: {
connect: {
id_linked_user: await this.connectionUtils.getLinkedUserId(
projectId,
linkedUserId,
),
},
},
},
});
}
return db_res;
} catch (error) {
throw error;
}
}
}
2 changes: 1 addition & 1 deletion packages/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Sentry from '@sentry/node';
import '@@core/sentry/instrument';
import * as Sentry from '@sentry/node';
import {
BaseExceptionFilter,
HttpAdapterHost,
Expand Down
3 changes: 1 addition & 2 deletions packages/shared/src/connectors/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ export const CONNECTORS_METADATA: ProvidersConfig = {
authStrategy: AuthStrategy.api_key
},
'affinity': {
scopes: '',
urls: {
docsUrl: 'https://api-docs.affinity.co/#getting-started',
apiUrl: 'https://api.affinity.co',
},
logoPath: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTMRfcwBA9Jn9z9dJQgY3f_H-bBeUzl-jRHNOm8xrmwtA&s',
logoPath: 'https://media.licdn.com/dms/image/C4D0BAQFOaK6KXEYj_w/company-logo_200_200/0/1630489791871/project_affinity_logo?e=2147483647&v=beta&t=u8j-1u3nO2m6vqgT170WJMCJyFSDiLYS_VguYOllNMI',
description: 'Sync & Create contacts, deals, companies, notes, engagements, stages, tasks and users',
active: false,
authStrategy: AuthStrategy.api_key
Expand Down

0 comments on commit 2312f42

Please sign in to comment.