Skip to content

Commit

Permalink
🐛 Fix prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jun 17, 2024
1 parent cc919b2 commit 5099e45
Show file tree
Hide file tree
Showing 497 changed files with 20,770 additions and 2,943 deletions.
2 changes: 1 addition & 1 deletion ngrok.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
version: 2
authtoken: NGROK_TOKEN
authtoken: NGROK_AUTH
log_level: debug
log: stdout

Expand Down
2 changes: 1 addition & 1 deletion packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ model fs_permissions {
type String[]
roles String[]
}

model fs_shared_links {
id_fs_shared_link String @id(map: "pk_fs_shared_links") @db.Uuid
created_at DateTime @db.Timestamp(6)
Expand Down
11 changes: 7 additions & 4 deletions packages/api/scripts/commonObject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ import { ApiResponse } from '@@core/utils/types';
import { throwTypedError, Unified${VerticalCap}Error } from '@@core/utils/errors';
import { WebhookService } from '@@core/webhook/webhook.service';
import { Unified${ObjectCap}Input, Unified${ObjectCap}Output } from '../types/model.unified';
import { desunify } from '@@core/utils/unification/desunify';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ServiceRegistry } from './registry.service';
import { Original${ObjectCap}Output } from '@@core/utils/types/original/original.${VerticalLow}';
import { unify } from '@@core/utils/unification/unify';
import { I${ObjectCap}Service } from '../types';
@Injectable()
Expand Down Expand Up @@ -137,7 +137,7 @@ import { ApiResponse } from '@@core/utils/types';
import { v4 as uuidv4 } from 'uuid';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ServiceRegistry } from '../services/registry.service';
import { unify } from '@@core/utils/unification/unify';
import { ${VerticalCap}Object } from '@${VerticalLow}/@utils/@types';
import { WebhookService } from '@@core/webhook/webhook.service';
import { Unified${ObjectCap}Output } from '../types/model.unified';
Expand Down Expand Up @@ -238,6 +238,7 @@ import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'
import { PrismaService } from '@@core/prisma/prisma.service';
import { WebhookService } from '@@core/webhook/webhook.service';
import { BullModule } from '@nestjs/bull';
import { ConnectionUtils } from '@@core/connections/@utils';
@Module({
imports: [
Expand All @@ -255,6 +256,7 @@ import { BullModule } from '@nestjs/bull';
EncryptionService,
FieldMappingService,
ServiceRegistry,
ConnectionUtils,
/* PROVIDERS SERVICES */
],
Expand Down Expand Up @@ -293,11 +295,12 @@ import { ConnectionUtils } from '@@core/connections/@utils';
@ApiTags('${VerticalLow}/${objectType}')
@Controller('${VerticalLow}/${objectType}')
export class ${ObjectCap}Controller {
private readonly connectionUtils = new ConnectionUtils();
constructor(
private readonly ${objectType}Service: ${ObjectCap}Service,
private logger: LoggerService,
private connectionUtils: ConnectionUtils
) {
this.logger.setContext(${ObjectCap}Controller.name);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/api/scripts/oauthConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class ${providerUpper}ConnectionService implements I${verticalUpper}Conne
private env: EnvironmentService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
) {
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils, ) {
this.logger.setContext(${providerUpper}ConnectionService.name);
this.registry.registerService('${provider.toLowerCase()}', this);
this.type = providerToType('${provider.toLowerCase()}', '${vertical.toLowerCase()}', AuthStrategy.oauth2);
Expand Down
8 changes: 4 additions & 4 deletions packages/api/scripts/seed.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
INSERT INTO users (id_user, identification_strategy, email, password_hash, first_name, last_name) VALUES
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','[email protected]', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora', TRUE, TRUE);
('0ce39030-2901-4c56-8db0-5e326182ec6b', 'b2c','[email protected]', '$2b$10$Y7Q8TWGyGuc5ecdIASbBsuXMo3q/Rs3/cnY.mLZP4tUgfGUOCUBlG', 'local', 'Panora');

INSERT INTO connector_sets (id_connector_set, crm_hubspot, crm_zoho, crm_pipedrive, crm_attio, crm_zendesk, crm_close, tcg_zendesk, tcg_gorgias, tcg_front, tcg_jira, tcg_gitlab) VALUES
('1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE),
('aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE);

INSERT INTO projects (id_project, name, sync_mode, id_user, id_connector_set) VALUES
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7', TRUE, TRUE),
('4c641a21-a7f8-4ffe-b7e8-e7d32db87557', 'Project 2', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '852dfff8-ab63-4530-ae49-e4b2924407f8', TRUE, TRUE),
('2b198012-c79c-4bb6-971e-9635830e8c15', 'Project 3', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', 'aed0f856-f802-4a79-8640-66d441581a99', TRUE, TRUE);
('1e468c15-aa57-4448-aa2b-7fed640d1e3d', 'Project 1', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '1709da40-17f7-4d3a-93a0-96dc5da6ddd7'),
('4c641a21-a7f8-4ffe-b7e8-e7d32db87557', 'Project 2', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', '852dfff8-ab63-4530-ae49-e4b2924407f8'),
('2b198012-c79c-4bb6-971e-9635830e8c15', 'Project 3', 'pool', '0ce39030-2901-4c56-8db0-5e326182ec6b', 'aed0f856-f802-4a79-8640-66d441581a99');
10 changes: 4 additions & 6 deletions packages/api/src/@core/connections/@utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { PrismaService } from '@@core/prisma/prisma.service';
import { ConnectionsError, throwTypedError } from '@@core/utils/errors';
import { PrismaClient } from '@prisma/client';
import { Injectable } from '@nestjs/common';
import { v4 as uuidv4 } from 'uuid';

export type ConnectionMetadata = {
linkedUserId: string;
remoteSource: string;
};

@Injectable()
export class ConnectionUtils {
private readonly prisma: PrismaClient;

constructor() {
this.prisma = new PrismaClient();
}
constructor(private readonly prisma: PrismaService) {}

async getConnectionMetadataFromConnectionToken(
token: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { QuickbooksConnectionService } from './services/quickbooks/quickbooks.se
import { SageConnectionService } from './services/sage/sage.service';
import { WaveFinancialConnectionService } from './services/wave_financial/wave_financial.service';
import { XeroConnectionService } from './services/xero/xero.service';
import { ConnectionUtils } from '../@utils';

@Module({
imports: [WebhookModule],
Expand All @@ -28,6 +29,7 @@ import { XeroConnectionService } from './services/xero/xero.service';
EncryptionService,
ServiceRegistry,
ConnectionsStrategiesService,
ConnectionUtils,
//PROVIDERS SERVICES,
PennylaneConnectionService,
FreeagentConnectionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class FreeagentConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -45,6 +44,7 @@ export class FreeagentConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(FreeagentConnectionService.name);
this.registry.registerService('freeagent', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class FreshbooksConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -45,6 +44,7 @@ export class FreshbooksConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(FreshbooksConnectionService.name);
this.registry.registerService('freshbooks', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class MoneybirdConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -46,6 +45,7 @@ export class MoneybirdConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(MoneybirdConnectionService.name);
this.registry.registerService('moneybird', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export class PennylaneConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -44,6 +43,7 @@ export class PennylaneConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(PennylaneConnectionService.name);
this.registry.registerService('pennylane', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export class QuickbooksConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -45,6 +44,7 @@ export class QuickbooksConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(QuickbooksConnectionService.name);
this.registry.registerService('quickbooks', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export type SageOAuthResponse = {
@Injectable()
export class SageConnectionService implements IAccountingConnectionService {
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -45,6 +44,7 @@ export class SageConnectionService implements IAccountingConnectionService {
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(SageConnectionService.name);
this.registry.registerService('sage', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class WaveFinancialConnectionService
implements IAccountingConnectionService
{
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -47,6 +46,7 @@ export class WaveFinancialConnectionService
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(WaveFinancialConnectionService.name);
this.registry.registerService('wave_financial', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function decodeJWT(token: string): DecodedJWTToken {
@Injectable()
export class XeroConnectionService implements IAccountingConnectionService {
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
Expand All @@ -70,6 +69,7 @@ export class XeroConnectionService implements IAccountingConnectionService {
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(XeroConnectionService.name);
this.registry.registerService('xero', this);
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/@core/connections/connections.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TicketModule } from '@ticketing/ticket/ticket.module';
import { UserModule as TUserModule } from '@ticketing/user/user.module';
import { FilestorageConnectionModule } from './filestorage/filestorage.connection.module';
import { HrisConnectionModule } from './hris/hris.connection.module';
import { ConnectionUtils } from './@utils';

@Module({
controllers: [ConnectionsController],
Expand Down Expand Up @@ -58,6 +59,7 @@ import { HrisConnectionModule } from './hris/hris.connection.module';
PrismaService,
ValidateUserService,
CoreSyncService,
ConnectionUtils,
],
exports: [
CrmConnectionModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { ConnectionsStrategiesService } from '@@core/connections-strategies/conn
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';

@Module({
imports: [WebhookModule],
Expand All @@ -28,6 +29,7 @@ import { TeamleaderConnectionService } from './services/teamleader/teamleader.se
EnvironmentService,
EncryptionService,
ConnectionsStrategiesService,
ConnectionUtils,
// PROVIDERS SERVICES
HubspotConnectionService,
AttioConnectionService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,14 @@ type AcceloOAuthResponse = {
@Injectable()
export class AcceloConnectionService implements ICrmConnectionService {
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
private logger: LoggerService,
private env: EnvironmentService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(AcceloConnectionService.name);
this.registry.registerService('accelo', this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
import { PrismaService } from '@@core/prisma/prisma.service';
import axios from 'axios';
import { v4 as uuidv4 } from 'uuid';
import { Action, ActionType, ConnectionsError, format3rdPartyError, throwTypedError } from '@@core/utils/errors';
import {
Action,
ActionType,
ConnectionsError,
format3rdPartyError,
throwTypedError,
} from '@@core/utils/errors';
import { EnvironmentService } from '@@core/environment/environment.service';
import { EncryptionService } from '@@core/encryption/encryption.service';
import { ServiceRegistry } from '../registry.service';
Expand All @@ -29,15 +35,14 @@ export interface AttioOAuthResponse {
@Injectable()
export class AttioConnectionService implements ICrmConnectionService {
private readonly type: string;
private readonly connectionUtils = new ConnectionUtils();

constructor(
private prisma: PrismaService,
private logger: LoggerService,
private env: EnvironmentService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
private cService: ConnectionsStrategiesService,
private connectionUtils: ConnectionUtils,
) {
this.logger.setContext(AttioConnectionService.name);
this.registry.registerService('attio', this);
Expand Down Expand Up @@ -131,17 +136,18 @@ export class AttioConnectionService implements ICrmConnectionService {
this.logger.log('Successfully added tokens inside DB ' + db_res);
return db_res;
} catch (error) {
throwTypedError(new ConnectionsError(
{
name: "HANDLE_OAUTH_CALLBACK_CRM",
throwTypedError(
new ConnectionsError({
name: 'HANDLE_OAUTH_CALLBACK_CRM',
message: `AttioConnectionService.handleCallback() call failed ---> ${format3rdPartyError(
"attio",
'attio',
Action.oauthCallback,
ActionType.POST
ActionType.POST,
)}`,
cause: error
}
), this.logger)
cause: error,
}),
this.logger,
);
}
}

Expand Down
Loading

0 comments on commit 5099e45

Please sign in to comment.