Skip to content

Commit

Permalink
🔥 Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jan 8, 2024
1 parent 01c2297 commit f95962d
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 194 deletions.
46 changes: 13 additions & 33 deletions INTEGRATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ import { CallbackParams, ICrmConnectionService, RefreshParams } from '../../type

@Injectable()
export class My3rdPartyConnectionService implements ICrmConnectionService {
constructor(
private prisma: PrismaService,
private logger: LoggerService,
private env: EnvironmentService,
private cryptoService: EncryptionService,
private registry: ServiceRegistry,
) {
this.logger.setContext(My3rdPartyConnectionService.name);
this.registry.registerService('insert_the_name_of_your_3rd_party', this);
}

async handleCallback(
opts: CallbackParams
) {
Expand All @@ -71,38 +82,7 @@ Now that you have the structure, check other 3rd parties implementations under `

## 2. Enable your connection service to handle oAuth granting access

`cd @core/connections/crm/services/registry.service.ts`

Add your new 3rd party service to the `registry` service.

```ts
//ADD YOUR IMPORT
import { My3rdPartyConnectionService } from './my3rdParty/my3rdParty.service';

@Injectable()
export class ServiceConnectionRegistry {
private serviceMap: Map<string, ICrmConnectionService>;

constructor(
freshsales: FreshsalesConnectionService,
hubspot: HubspotConnectionService,
zoho: ZohoConnectionService,
zendesk: ZendeskConnectionService,
pipedrive: PipedriveConnectionService,
) {
this.serviceMap = new Map<string, ICrmConnectionService>();
this.serviceMap.set('freshsales', freshsales);
this.serviceMap.set('hubspot', hubspot);
this.serviceMap.set('zoho', zoho);
this.serviceMap.set('zendesk', zendesk);
this.serviceMap.set('pipedrive', pipedrive);
//ADD YOUR SERVICE
this.serviceMap.set('my3rdParty', my3rdParty);
}
}
```

Don't forget to ddd your service to the `CrmConnectionModule` module !
Add your service to the `CrmConnectionModule` under `@core/connections/crm/crm.connection.module.ts` module !

```ts
@Module({
Expand Down Expand Up @@ -171,7 +151,7 @@ export class My3rdPartyService implements IContactService {
this.logger.setContext(
CrmObject.contact.toUpperCase() + ':' + My3rdPartyService.name,
);
this.registry.registerService('my3rdPartyService', this);
this.registry.registerService('insert_the_name_of_your_3rd_party', this);

}
async addContact(
Expand Down
1 change: 1 addition & 0 deletions packages/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ model connections {
refresh_token String?
expiration_timestamp DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
connection_token String?
id_project String @db.Uuid
id_linked_user String @db.Uuid
linked_users linked_users @relation(fields: [id_linked_user], references: [id_linked_user], onDelete: NoAction, onUpdate: NoAction, map: "fk_11")
Expand Down
38 changes: 18 additions & 20 deletions packages/api/src/crm/contact/services/contact.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { PrismaService } from '@@core/prisma/prisma.service';
import { ContactResponse, IContactService } from '../types';
import { IContactService } from '../types';
import { desunify } from '@@core/utils/unification/desunify';
import { CrmObject } from '@crm/@utils/@types';
import { LoggerService } from '@@core/logger/logger.service';
Expand Down Expand Up @@ -230,25 +230,23 @@ export class ContactService {
}
}
}
if (remote_data) {
//insert remote_data in db
await this.prisma.remote_data.upsert({
where: {
ressource_owner_id: unique_crm_contact_id,
},
create: {
id_remote_data: uuidv4(),
ressource_owner_id: unique_crm_contact_id,
format: 'json',
data: JSON.stringify(source_contact),
created_at: new Date(),
},
update: {
data: JSON.stringify(source_contact),
created_at: new Date(),
},
});
}
//insert remote_data in db
await this.prisma.remote_data.upsert({
where: {
ressource_owner_id: unique_crm_contact_id,
},
create: {
id_remote_data: uuidv4(),
ressource_owner_id: unique_crm_contact_id,
format: 'json',
data: JSON.stringify(source_contact),
created_at: new Date(),
},
update: {
data: JSON.stringify(source_contact),
created_at: new Date(),
},
});

const result_contact = await this.getContact(
unique_crm_contact_id,
Expand Down
7 changes: 0 additions & 7 deletions packages/api/src/crm/contact/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,3 @@ export type NormalizedContactInfo = {
normalizedEmails: Email[];
normalizedPhones: Phone[];
};

export class ContactResponse {
@ApiProperty({ type: [UnifiedContactOutput] })
contacts: UnifiedContactOutput[];
@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; //data in original format
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { LoggerService } from '@@core/logger/logger.service';
import { v4 as uuidv4 } from 'uuid';
import { handleServiceError } from '@@core/utils/errors';
import { UnifiedAccountOutput } from '../types/model.unified';
import { AccountResponse } from '../types';

@Injectable()
export class AccountService {
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/ticketing/account/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { UnifiedAccountInput, UnifiedAccountOutput } from './model.unified';
import { OriginalAccountOutput } from '@@core/utils/types/original/original.ticketing';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';

export interface IAccountService {
Expand All @@ -28,11 +27,3 @@ export interface IAccountMapper {
}[],
): UnifiedAccountOutput | UnifiedAccountOutput[];
}

export class AccountResponse {
@ApiProperty({ type: [UnifiedAccountOutput] })
accounts: UnifiedAccountOutput[];

@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; // Data in original format
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
UnifiedAttachmentInput,
UnifiedAttachmentOutput,
} from '../types/model.unified';
import { AttachmentResponse } from '../types';

@Injectable()
export class AttachmentService {
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/ticketing/attachment/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
UnifiedAttachmentInput,
UnifiedAttachmentOutput,
} from './model.unified';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';
import { OriginalAttachmentOutput } from '@@core/utils/types/original/original.ticketing';

Expand Down Expand Up @@ -36,11 +35,3 @@ export interface IAttachmentMapper {
}[],
): UnifiedAttachmentOutput | UnifiedAttachmentOutput[];
}

export class AttachmentResponse {
@ApiProperty({ type: [UnifiedAttachmentOutput] })
attachments: UnifiedAttachmentOutput[];

@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; // Data in original format
}
36 changes: 17 additions & 19 deletions packages/api/src/ticketing/comment/services/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,25 +240,23 @@ export class CommentService {
unique_ticketing_comment_id = res.id_tcg_comment;
}

if (remote_data) {
//insert remote_data in db
await this.prisma.remote_data.upsert({
where: {
ressource_owner_id: unique_ticketing_comment_id,
},
create: {
id_remote_data: uuidv4(),
ressource_owner_id: unique_ticketing_comment_id,
format: 'json',
data: JSON.stringify(source_comment),
created_at: new Date(),
},
update: {
data: JSON.stringify(source_comment),
created_at: new Date(),
},
});
}
//insert remote_data in db
await this.prisma.remote_data.upsert({
where: {
ressource_owner_id: unique_ticketing_comment_id,
},
create: {
id_remote_data: uuidv4(),
ressource_owner_id: unique_ticketing_comment_id,
format: 'json',
data: JSON.stringify(source_comment),
created_at: new Date(),
},
update: {
data: JSON.stringify(source_comment),
created_at: new Date(),
},
});

const result_comment = await this.getComment(
unique_ticketing_comment_id,
Expand Down
8 changes: 0 additions & 8 deletions packages/api/src/ticketing/comment/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { UnifiedCommentInput, UnifiedCommentOutput } from './model.unified';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';
import { OriginalCommentOutput } from '@@core/utils/types/original/original.ticketing';

Expand Down Expand Up @@ -41,10 +40,3 @@ export type Comment = {
html_body: string;
is_private: boolean;
};

export class CommentResponse {
@ApiProperty({ type: [UnifiedCommentOutput] })
comments: UnifiedCommentOutput[];
@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; //data in original format
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ 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 { ApiResponse } from '@@core/utils/types';
import { handleServiceError } from '@@core/utils/errors';
import { UnifiedContactOutput } from '../types/model.unified';
import { ContactResponse } from '../types';

@Injectable()
export class ContactService {
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/ticketing/contact/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { UnifiedContactInput, UnifiedContactOutput } from './model.unified';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';
import { OriginalContactOutput } from '@@core/utils/types/original/original.ticketing';

Expand Down Expand Up @@ -28,11 +27,3 @@ export interface IContactMapper {
}[],
): UnifiedContactOutput | UnifiedContactOutput[];
}

export class ContactResponse {
@ApiProperty({ type: [UnifiedContactOutput] })
contacts: UnifiedContactOutput[];

@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; // Data in original format
}
2 changes: 0 additions & 2 deletions packages/api/src/ticketing/tag/services/tag.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ 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 { ApiResponse } from '@@core/utils/types';
import { handleServiceError } from '@@core/utils/errors';
import { UnifiedTagOutput } from '../types/model.unified';
import { TagResponse } from '../types';

@Injectable()
export class TagService {
Expand Down
14 changes: 1 addition & 13 deletions packages/api/src/ticketing/tag/tag.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import {
Controller,
Post,
Body,
Query,
Get,
Patch,
Param,
Headers,
} from '@nestjs/common';
import { Controller, Query, Get, Param, Headers } from '@nestjs/common';
import { LoggerService } from '@@core/logger/logger.service';
import {
ApiBody,
ApiOperation,
ApiParam,
ApiQuery,
Expand All @@ -19,8 +9,6 @@ import {
} from '@nestjs/swagger';
import { ApiCustomResponse } from '@@core/utils/types';
import { TagService } from './services/tag.service';
import { TagResponse } from './types';
import { UnifiedTagInput } from './types/model.unified';

@ApiTags('ticketing/tag')
@Controller('ticketing/tag')
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/ticketing/tag/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { UnifiedTagInput, UnifiedTagOutput } from './model.unified';
import { OriginalTagOutput } from '@@core/utils/types/original/original.ticketing';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';

export interface ITagService {
Expand All @@ -28,11 +27,3 @@ export interface ITagMapper {
}[],
): UnifiedTagOutput | UnifiedTagOutput[];
}

export class TagResponse {
@ApiProperty({ type: [UnifiedTagOutput] })
tags: UnifiedTagOutput[];

@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; // Data in original format
}
2 changes: 0 additions & 2 deletions packages/api/src/ticketing/team/services/team.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ 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 { ApiResponse } from '@@core/utils/types';
import { handleServiceError } from '@@core/utils/errors';
import { UnifiedTeamOutput } from '../types/model.unified';
import { TeamResponse } from '../types';

@Injectable()
export class TeamService {
Expand Down
9 changes: 0 additions & 9 deletions packages/api/src/ticketing/team/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DesunifyReturnType } from '@@core/utils/types/desunify.input';
import { UnifiedTeamInput, UnifiedTeamOutput } from './model.unified';
import { OriginalTeamOutput } from '@@core/utils/types/original/original.ticketing';
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ApiResponse } from '@@core/utils/types';

export interface ITeamService {
Expand All @@ -28,11 +27,3 @@ export interface ITeamMapper {
}[],
): UnifiedTeamOutput | UnifiedTeamOutput[];
}

export class TeamResponse {
@ApiProperty({ type: [UnifiedTeamOutput] })
teams: UnifiedTeamOutput[];

@ApiPropertyOptional({ type: [{}] })
remote_data?: Record<string, any>[]; // Data in original format
}
Loading

0 comments on commit f95962d

Please sign in to comment.