From 72579894daf890662a2d180762a4bf4d94f0b3ca Mon Sep 17 00:00:00 2001 From: nael Date: Fri, 29 Dec 2023 21:44:16 +0100 Subject: [PATCH] :ambulance: Added a lot of fixes --- .../environment/environement.validation.ts | 4 +- .../api/src/crm/contact/contact.module.ts | 4 +- .../crm/contact/services/contact.service.ts | 4 +- .../services}/registry.service.ts | 12 +++--- .../api/src/crm/contact/sync/sync.service.ts | 4 +- packages/api/src/crm/crm.module.ts | 2 +- .../@utils/@registry/registry.service.ts | 21 ---------- .../api/src/ticketing/@utils/@types/index.ts | 10 ++++- .../ticketing/attachment/attachment.module.ts | 27 +++++++++++++ .../attachment/services/attachment.service.ts | 4 +- .../attachment/services/registry.service.ts | 22 ++++++++++ .../attachment/services/zendesk/index.ts | 40 +++++++++++++++++++ .../ticketing/attachment/sync/sync.service.ts | 4 +- .../src/ticketing/comment/comment.module.ts | 8 +++- .../comment/services/comment.service.ts | 8 ++-- .../comment/services/registry.service.ts | 22 ++++++++++ .../comment/services/zendesk/index.ts | 4 +- .../ticketing/comment/sync/sync.service.ts | 4 +- .../ticketing/contact/contact.controller.ts | 32 +++++++++++++++ .../src/ticketing/contact/contact.module.ts | 34 ++++++++++++++++ .../contact/services/contact.service.ts | 4 +- .../contact/services/registry.service.ts | 22 ++++++++++ .../contact/services/zendesk/index.ts | 36 +++++++++++++++++ .../ticketing/contact/sync/sync.service.ts | 4 +- .../ticket/services/registry.service.ts | 22 ++++++++++ .../ticket/services/ticket.service.ts | 8 ++-- .../ticket/services/zendesk/index.ts | 4 +- .../src/ticketing/ticket/sync/sync.service.ts | 4 +- .../api/src/ticketing/ticket/ticket.module.ts | 8 +++- .../api/src/ticketing/ticketing.module.ts | 17 +++++++- .../user/services/registry.service.ts | 22 ++++++++++ .../ticketing/user/services/user.service.ts | 4 +- .../ticketing/user/services/zendesk/index.ts | 35 ++++++++++++++++ .../src/ticketing/user/sync/sync.service.ts | 4 +- .../api/src/ticketing/user/user.controller.ts | 2 +- .../api/src/ticketing/user/user.module.ts | 27 +++++++++++++ 36 files changed, 421 insertions(+), 72 deletions(-) rename packages/api/src/crm/{@utils/@registry => contact/services}/registry.service.ts (78%) delete mode 100644 packages/api/src/ticketing/@utils/@registry/registry.service.ts create mode 100644 packages/api/src/ticketing/attachment/services/registry.service.ts create mode 100644 packages/api/src/ticketing/comment/services/registry.service.ts create mode 100644 packages/api/src/ticketing/contact/contact.controller.ts create mode 100644 packages/api/src/ticketing/contact/contact.module.ts create mode 100644 packages/api/src/ticketing/contact/services/registry.service.ts create mode 100644 packages/api/src/ticketing/ticket/services/registry.service.ts create mode 100644 packages/api/src/ticketing/user/services/registry.service.ts diff --git a/packages/api/src/@core/environment/environement.validation.ts b/packages/api/src/@core/environment/environement.validation.ts index 8e551b1e6..23fc14c9b 100644 --- a/packages/api/src/@core/environment/environement.validation.ts +++ b/packages/api/src/@core/environment/environement.validation.ts @@ -48,10 +48,10 @@ export class EnvVars { FRESHSALES_CLIENT_SECRET?: string; @IsString() - ZENDESK_CLIENT_ID: string; + ZENDESK_SELL_CLIENT_ID: string; @IsString() - ZENDESK_CLIENT_SECRET: string; + ZENDESK_SELL_CLIENT_SECRET: string; @IsString() ZENDESK_TICKETING_SUBDOMAIN: string; diff --git a/packages/api/src/crm/contact/contact.module.ts b/packages/api/src/crm/contact/contact.module.ts index 913be753f..61f67802f 100644 --- a/packages/api/src/crm/contact/contact.module.ts +++ b/packages/api/src/crm/contact/contact.module.ts @@ -13,7 +13,7 @@ import { SyncContactsService } from './sync/sync.service'; import { WebhookService } from '@@core/webhook/webhook.service'; import { BullModule } from '@nestjs/bull'; import { EncryptionService } from '@@core/encryption/encryption.service'; -import { ServiceRegistry } from '../@utils/@registry/registry.service'; +import { ContactServiceRegistry } from './services/registry.service'; @Module({ imports: [ @@ -35,7 +35,7 @@ import { ServiceRegistry } from '../@utils/@registry/registry.service'; SyncContactsService, WebhookService, EncryptionService, - ServiceRegistry, + ContactServiceRegistry, ], exports: [SyncContactsService], }) diff --git a/packages/api/src/crm/contact/services/contact.service.ts b/packages/api/src/crm/contact/services/contact.service.ts index 1865070fc..c615ab48f 100644 --- a/packages/api/src/crm/contact/services/contact.service.ts +++ b/packages/api/src/crm/contact/services/contact.service.ts @@ -15,8 +15,8 @@ import { handleServiceError } from '@@core/utils/errors'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; import { WebhookService } from '@@core/webhook/webhook.service'; import { normalizeEmailsAndNumbers } from '@crm/contact/utils'; -import { ServiceRegistry } from '../../@utils/@registry/registry.service'; import { OriginalContactOutput } from '@@core/utils/types/original/original.crm'; +import { ContactServiceRegistry } from './registry.service'; @Injectable() export class ContactService { @@ -25,7 +25,7 @@ export class ContactService { private logger: LoggerService, private fieldMappingService: FieldMappingService, private webhook: WebhookService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: ContactServiceRegistry, ) { this.logger.setContext(ContactService.name); } diff --git a/packages/api/src/crm/@utils/@registry/registry.service.ts b/packages/api/src/crm/contact/services/registry.service.ts similarity index 78% rename from packages/api/src/crm/@utils/@registry/registry.service.ts rename to packages/api/src/crm/contact/services/registry.service.ts index 174c363b5..d35397c46 100644 --- a/packages/api/src/crm/@utils/@registry/registry.service.ts +++ b/packages/api/src/crm/contact/services/registry.service.ts @@ -4,11 +4,11 @@ import { HubspotService } from '@crm/contact/services/hubspot'; import { ZohoService } from '@crm/contact/services/zoho'; import { ZendeskService } from '@crm/contact/services/zendesk'; import { PipedriveService } from '@crm/contact/services/pipedrive'; -import { ICrmService } from '../@types'; +import { IContactService } from '../types'; @Injectable() -export class ServiceRegistry { - private serviceMap: Map; +export class ContactServiceRegistry { + private serviceMap: Map; constructor( freshsales: FreshSalesService, @@ -18,7 +18,7 @@ export class ServiceRegistry { pipedrive: PipedriveService, ) { //TODO - this.serviceMap = new Map(); + this.serviceMap = new Map(); this.serviceMap.set('freshsales', freshsales); this.serviceMap.set('hubspot', hubspot); this.serviceMap.set('zoho', zoho); @@ -26,11 +26,11 @@ export class ServiceRegistry { this.serviceMap.set('pipedrive', pipedrive); } - getService(integrationId: string): T { + getService(integrationId: string): IContactService { const service = this.serviceMap.get(integrationId); if (!service) { throw new Error(`Service not found for integration ID: ${integrationId}`); } - return service as T; + return service; } } diff --git a/packages/api/src/crm/contact/sync/sync.service.ts b/packages/api/src/crm/contact/sync/sync.service.ts index aab63070b..4e0003367 100644 --- a/packages/api/src/crm/contact/sync/sync.service.ts +++ b/packages/api/src/crm/contact/sync/sync.service.ts @@ -12,9 +12,9 @@ import { Injectable, OnModuleInit } from '@nestjs/common'; import { Cron } from '@nestjs/schedule'; import { v4 as uuidv4 } from 'uuid'; import { crm_contacts as CrmContact } from '@prisma/client'; -import { ServiceRegistry } from '@crm/@utils/@registry/registry.service'; import { IContactService } from '../types'; import { OriginalContactOutput } from '@@core/utils/types/original/original.crm'; +import { ContactServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncContactsService implements OnModuleInit { @@ -23,7 +23,7 @@ export class SyncContactsService implements OnModuleInit { private logger: LoggerService, private fieldMappingService: FieldMappingService, private webhook: WebhookService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: ContactServiceRegistry, ) { this.logger.setContext(SyncContactsService.name); } diff --git a/packages/api/src/crm/crm.module.ts b/packages/api/src/crm/crm.module.ts index 22b005854..d9bd601ca 100644 --- a/packages/api/src/crm/crm.module.ts +++ b/packages/api/src/crm/crm.module.ts @@ -6,6 +6,6 @@ import { DealModule } from './deal/deal.module'; imports: [ContactModule, DealModule], providers: [], controllers: [], - exports: [ContactModule], + exports: [ContactModule, DealModule], }) export class CrmModule {} diff --git a/packages/api/src/ticketing/@utils/@registry/registry.service.ts b/packages/api/src/ticketing/@utils/@registry/registry.service.ts deleted file mode 100644 index 1b45f75d2..000000000 --- a/packages/api/src/ticketing/@utils/@registry/registry.service.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import { ZendeskService } from '@ticketing/ticket/services/zendesk'; -import { ITicketingService } from '../@types'; - -@Injectable() -export class ServiceRegistry { - private serviceMap: Map; - - constructor(zendesk: ZendeskService) { - this.serviceMap = new Map(); - this.serviceMap.set('zendesk_t', zendesk); - } - - getService(integrationId: string): T { - const service = this.serviceMap.get(integrationId); - if (!service) { - throw new Error(`Service not found for integration ID: ${integrationId}`); - } - return service as T; - } -} diff --git a/packages/api/src/ticketing/@utils/@types/index.ts b/packages/api/src/ticketing/@utils/@types/index.ts index acb17a541..09c40be41 100644 --- a/packages/api/src/ticketing/@utils/@types/index.ts +++ b/packages/api/src/ticketing/@utils/@types/index.ts @@ -1,15 +1,18 @@ +import { IAttachmentService } from '@ticketing/attachment/types'; import { ICommentService } from '@ticketing/comment/types'; import { commentUnificationMapping } from '@ticketing/comment/types/mappingsTypes'; import { UnifiedCommentInput, UnifiedCommentOutput, } from '@ticketing/comment/types/model.unified'; +import { IContactService } from '@ticketing/contact/types'; import { ITicketService } from '@ticketing/ticket/types'; import { ticketUnificationMapping } from '@ticketing/ticket/types/mappingsTypes'; import { UnifiedTicketInput, UnifiedTicketOutput, } from '@ticketing/ticket/types/model.unified'; +import { IUserService } from '@ticketing/user/types'; export enum TicketingObject { ticket = 'ticket', @@ -30,7 +33,12 @@ export const unificationMapping = { [TicketingObject.comment]: commentUnificationMapping, }; -export type ITicketingService = ITicketService | ICommentService; +export type ITicketingService = + | ITicketService + | ICommentService + | IUserService + | IAttachmentService + | IContactService; export * from '../../ticket/services/zendesk/types'; export * from '../../comment/services/zendesk/types'; diff --git a/packages/api/src/ticketing/attachment/attachment.module.ts b/packages/api/src/ticketing/attachment/attachment.module.ts index 988307fd8..a624e9563 100644 --- a/packages/api/src/ticketing/attachment/attachment.module.ts +++ b/packages/api/src/ticketing/attachment/attachment.module.ts @@ -1,7 +1,34 @@ import { Module } from '@nestjs/common'; import { AttachmentController } from './attachment.controller'; +import { SyncAttachmentsService } from './sync/sync.service'; +import { LoggerService } from '@@core/logger/logger.service'; +import { ZendeskAttachmentService } from './services/zendesk'; +import { AttachmentService } from './services/attachment.service'; +import { AttachmentServiceRegistry } from './services/registry.service'; +import { EncryptionService } from '@@core/encryption/encryption.service'; +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'; @Module({ + imports: [ + BullModule.registerQueue({ + name: 'webhookDelivery', + }), + ], controllers: [AttachmentController], + providers: [ + AttachmentService, + PrismaService, + ZendeskAttachmentService, + LoggerService, + SyncAttachmentsService, + WebhookService, + EncryptionService, + FieldMappingService, + AttachmentServiceRegistry, + ], + exports: [SyncAttachmentsService], }) export class AttachmentModule {} diff --git a/packages/api/src/ticketing/attachment/services/attachment.service.ts b/packages/api/src/ticketing/attachment/services/attachment.service.ts index a214023d9..367de12a7 100644 --- a/packages/api/src/ticketing/attachment/services/attachment.service.ts +++ b/packages/api/src/ticketing/attachment/services/attachment.service.ts @@ -13,8 +13,8 @@ import { AttachmentResponse } from '../types'; import { desunify } from '@@core/utils/unification/desunify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; +import { AttachmentServiceRegistry } from './registry.service'; @Injectable() export class AttachmentService { @@ -23,7 +23,7 @@ export class AttachmentService { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: AttachmentServiceRegistry, ) { this.logger.setContext(AttachmentService.name); } diff --git a/packages/api/src/ticketing/attachment/services/registry.service.ts b/packages/api/src/ticketing/attachment/services/registry.service.ts new file mode 100644 index 000000000..0382dca80 --- /dev/null +++ b/packages/api/src/ticketing/attachment/services/registry.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { IAttachmentService } from '../types'; +import { ZendeskAttachmentService } from './zendesk'; + +@Injectable() +export class AttachmentServiceRegistry { + private serviceMap: Map; + + constructor(zendesk: ZendeskAttachmentService) { + //TODO + this.serviceMap = new Map(); + this.serviceMap.set('zendesk_t', zendesk); + } + + getService(integrationId: string): IAttachmentService { + const service = this.serviceMap.get(integrationId); + if (!service) { + throw new Error(`Service not found for integration ID: ${integrationId}`); + } + return service; + } +} diff --git a/packages/api/src/ticketing/attachment/services/zendesk/index.ts b/packages/api/src/ticketing/attachment/services/zendesk/index.ts index e69de29bb..f62247706 100644 --- a/packages/api/src/ticketing/attachment/services/zendesk/index.ts +++ b/packages/api/src/ticketing/attachment/services/zendesk/index.ts @@ -0,0 +1,40 @@ +import { EncryptionService } from '@@core/encryption/encryption.service'; +import { EnvironmentService } from '@@core/environment/environment.service'; +import { LoggerService } from '@@core/logger/logger.service'; +import { PrismaService } from '@@core/prisma/prisma.service'; +import { ApiResponse } from '@@core/utils/types'; +import { DesunifyReturnType } from '@@core/utils/types/desunify.input'; +import { Injectable } from '@nestjs/common'; +import { + TicketingObject, + ZendeskAttachmentInput, +} from '@ticketing/@utils/@types'; +import { IAttachmentService } from '@ticketing/attachment/types'; + +@Injectable() +export class ZendeskAttachmentService implements IAttachmentService { + constructor( + private prisma: PrismaService, + private logger: LoggerService, + private cryptoService: EncryptionService, + private env: EnvironmentService, + ) { + this.logger.setContext( + TicketingObject.attachment.toUpperCase() + + ':' + + ZendeskAttachmentService.name, + ); + } + addAttachment( + attachmentData: DesunifyReturnType, + linkedUserId: string, + ): Promise> { + throw new Error('Method not implemented.'); + } + syncAttachments( + linkedUserId: string, + custom_properties?: string[], + ): Promise> { + throw new Error('Method not implemented.'); + } +} diff --git a/packages/api/src/ticketing/attachment/sync/sync.service.ts b/packages/api/src/ticketing/attachment/sync/sync.service.ts index e46100e94..e27c4fc08 100644 --- a/packages/api/src/ticketing/attachment/sync/sync.service.ts +++ b/packages/api/src/ticketing/attachment/sync/sync.service.ts @@ -6,12 +6,12 @@ import { Cron } from '@nestjs/schedule'; import { ApiResponse, TICKETING_PROVIDERS } from '@@core/utils/types'; import { v4 as uuidv4 } from 'uuid'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { WebhookService } from '@@core/webhook/webhook.service'; import { UnifiedAttachmentOutput } from '../types/model.unified'; import { IAttachmentService } from '../types'; +import { AttachmentServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncAttachmentsService implements OnModuleInit { @@ -20,7 +20,7 @@ export class SyncAttachmentsService implements OnModuleInit { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: AttachmentServiceRegistry, ) { this.logger.setContext(SyncAttachmentsService.name); } diff --git a/packages/api/src/ticketing/comment/comment.module.ts b/packages/api/src/ticketing/comment/comment.module.ts index 31e6343d0..f4d82b1ec 100644 --- a/packages/api/src/ticketing/comment/comment.module.ts +++ b/packages/api/src/ticketing/comment/comment.module.ts @@ -4,10 +4,12 @@ import { WebhookService } from '@@core/webhook/webhook.service'; import { EncryptionService } from '@@core/encryption/encryption.service'; import { LoggerService } from '@@core/logger/logger.service'; import { PrismaService } from '@@core/prisma/prisma.service'; -import { ZendeskService } from './services/zendesk'; +import { ZendeskCommentService } from './services/zendesk'; import { BullModule } from '@nestjs/bull'; import { CommentController } from './comment.controller'; import { CommentService } from './services/comment.service'; +import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; +import { CommentServiceRegistry } from './services/registry.service'; @Module({ imports: [ @@ -20,10 +22,12 @@ import { CommentService } from './services/comment.service'; CommentService, PrismaService, LoggerService, - ZendeskService, + ZendeskCommentService, SyncCommentsService, WebhookService, EncryptionService, + FieldMappingService, + CommentServiceRegistry, ], exports: [SyncCommentsService], }) diff --git a/packages/api/src/ticketing/comment/services/comment.service.ts b/packages/api/src/ticketing/comment/services/comment.service.ts index 08a308029..3b7f98849 100644 --- a/packages/api/src/ticketing/comment/services/comment.service.ts +++ b/packages/api/src/ticketing/comment/services/comment.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { PrismaService } from '@@core/prisma/prisma.service'; -import { ZendeskService } from './zendesk'; +import { ZendeskCommentService } from './zendesk'; import { LoggerService } from '@@core/logger/logger.service'; import { v4 as uuidv4 } from 'uuid'; import { ApiResponse } from '@@core/utils/types'; @@ -14,18 +14,18 @@ import { CommentResponse } from '../types'; import { desunify } from '@@core/utils/unification/desunify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; +import { CommentServiceRegistry } from './registry.service'; @Injectable() export class CommentService { constructor( private prisma: PrismaService, - private zendesk: ZendeskService, + private zendesk: ZendeskCommentService, private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: CommentServiceRegistry, ) { this.logger.setContext(CommentService.name); } diff --git a/packages/api/src/ticketing/comment/services/registry.service.ts b/packages/api/src/ticketing/comment/services/registry.service.ts new file mode 100644 index 000000000..0903d04b8 --- /dev/null +++ b/packages/api/src/ticketing/comment/services/registry.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { ZendeskCommentService } from './zendesk'; +import { ICommentService } from '../types'; + +@Injectable() +export class CommentServiceRegistry { + private serviceMap: Map; + + constructor(zendesk: ZendeskCommentService) { + //TODO + this.serviceMap = new Map(); + this.serviceMap.set('zendesk_t', zendesk); + } + + getService(integrationId: string): ICommentService { + const service = this.serviceMap.get(integrationId); + if (!service) { + throw new Error(`Service not found for integration ID: ${integrationId}`); + } + return service; + } +} diff --git a/packages/api/src/ticketing/comment/services/zendesk/index.ts b/packages/api/src/ticketing/comment/services/zendesk/index.ts index 2138ae0d7..d097cf5a1 100644 --- a/packages/api/src/ticketing/comment/services/zendesk/index.ts +++ b/packages/api/src/ticketing/comment/services/zendesk/index.ts @@ -13,7 +13,7 @@ import { ZendeskCommentOutput } from './types'; import { OriginalCommentOutput } from '@@core/utils/types/original/original.ticketing'; @Injectable() -export class ZendeskService implements ICommentService { +export class ZendeskCommentService implements ICommentService { constructor( private prisma: PrismaService, private logger: LoggerService, @@ -21,7 +21,7 @@ export class ZendeskService implements ICommentService { private env: EnvironmentService, ) { this.logger.setContext( - TicketingObject.comment.toUpperCase() + ':' + ZendeskService.name, + TicketingObject.comment.toUpperCase() + ':' + ZendeskCommentService.name, ); } async addComment( diff --git a/packages/api/src/ticketing/comment/sync/sync.service.ts b/packages/api/src/ticketing/comment/sync/sync.service.ts index d4efdc2ca..96b6193d6 100644 --- a/packages/api/src/ticketing/comment/sync/sync.service.ts +++ b/packages/api/src/ticketing/comment/sync/sync.service.ts @@ -6,7 +6,6 @@ import { Cron } from '@nestjs/schedule'; import { ApiResponse, TICKETING_PROVIDERS } from '@@core/utils/types'; import { v4 as uuidv4 } from 'uuid'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { WebhookService } from '@@core/webhook/webhook.service'; @@ -14,6 +13,7 @@ import { tcg_comments as TicketingComment } from '@prisma/client'; import { UnifiedCommentOutput } from '../types/model.unified'; import { ICommentService } from '../types'; import { OriginalCommentOutput } from '@@core/utils/types/original/original.ticketing'; +import { CommentServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncCommentsService implements OnModuleInit { @@ -22,7 +22,7 @@ export class SyncCommentsService implements OnModuleInit { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: CommentServiceRegistry, ) { this.logger.setContext(SyncCommentsService.name); } diff --git a/packages/api/src/ticketing/contact/contact.controller.ts b/packages/api/src/ticketing/contact/contact.controller.ts new file mode 100644 index 000000000..a1a8c3389 --- /dev/null +++ b/packages/api/src/ticketing/contact/contact.controller.ts @@ -0,0 +1,32 @@ +import { + Controller, + Post, + Body, + Query, + Get, + Patch, + Param, + Headers, +} from '@nestjs/common'; +import { LoggerService } from '@@core/logger/logger.service'; +import { + ApiBody, + ApiOperation, + ApiParam, + ApiQuery, + ApiTags, + ApiHeader, +} from '@nestjs/swagger'; +import { ContactService } from './services/contact.service'; +import { UnifiedContactInput } from './types/model.unified'; + +@ApiTags('ticketing/contact') +@Controller('ticketing/contact') +export class ContactController { + constructor( + private readonly contactService: ContactService, + private logger: LoggerService, + ) { + this.logger.setContext(ContactController.name); + } +} diff --git a/packages/api/src/ticketing/contact/contact.module.ts b/packages/api/src/ticketing/contact/contact.module.ts new file mode 100644 index 000000000..212ccb51a --- /dev/null +++ b/packages/api/src/ticketing/contact/contact.module.ts @@ -0,0 +1,34 @@ +import { Module } from '@nestjs/common'; +import { SyncContactsService } from './sync/sync.service'; +import { WebhookService } from '@@core/webhook/webhook.service'; +import { EncryptionService } from '@@core/encryption/encryption.service'; +import { LoggerService } from '@@core/logger/logger.service'; +import { PrismaService } from '@@core/prisma/prisma.service'; +import { ZendeskContactService } from './services/zendesk'; +import { BullModule } from '@nestjs/bull'; +import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; +import { ContactServiceRegistry } from './services/registry.service'; +import { ContactService } from './services/contact.service'; +import { ContactController } from './contact.controller'; + +@Module({ + imports: [ + BullModule.registerQueue({ + name: 'webhookDelivery', + }), + ], + controllers: [ContactController], + providers: [ + ContactService, + PrismaService, + LoggerService, + ZendeskContactService, + SyncContactsService, + WebhookService, + EncryptionService, + FieldMappingService, + ContactServiceRegistry, + ], + exports: [SyncContactsService], +}) +export class ContactModule {} diff --git a/packages/api/src/ticketing/contact/services/contact.service.ts b/packages/api/src/ticketing/contact/services/contact.service.ts index fe34e00ad..ae3c3d35a 100644 --- a/packages/api/src/ticketing/contact/services/contact.service.ts +++ b/packages/api/src/ticketing/contact/services/contact.service.ts @@ -13,8 +13,8 @@ import { ContactResponse } from '../types'; import { desunify } from '@@core/utils/unification/desunify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; +import { ContactServiceRegistry } from './registry.service'; @Injectable() export class ContactService { @@ -23,7 +23,7 @@ export class ContactService { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: ContactServiceRegistry, ) { this.logger.setContext(ContactService.name); } diff --git a/packages/api/src/ticketing/contact/services/registry.service.ts b/packages/api/src/ticketing/contact/services/registry.service.ts new file mode 100644 index 000000000..f7665ebaf --- /dev/null +++ b/packages/api/src/ticketing/contact/services/registry.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { IContactService } from '../types'; +import { ZendeskContactService } from './zendesk'; + +@Injectable() +export class ContactServiceRegistry { + private serviceMap: Map; + + constructor(zendesk: ZendeskContactService) { + //TODO + this.serviceMap = new Map(); + this.serviceMap.set('zendesk_t', zendesk); + } + + getService(integrationId: string): IContactService { + const service = this.serviceMap.get(integrationId); + if (!service) { + throw new Error(`Service not found for integration ID: ${integrationId}`); + } + return service; + } +} diff --git a/packages/api/src/ticketing/contact/services/zendesk/index.ts b/packages/api/src/ticketing/contact/services/zendesk/index.ts index e69de29bb..51861cdfe 100644 --- a/packages/api/src/ticketing/contact/services/zendesk/index.ts +++ b/packages/api/src/ticketing/contact/services/zendesk/index.ts @@ -0,0 +1,36 @@ +import { EncryptionService } from '@@core/encryption/encryption.service'; +import { EnvironmentService } from '@@core/environment/environment.service'; +import { LoggerService } from '@@core/logger/logger.service'; +import { PrismaService } from '@@core/prisma/prisma.service'; +import { ApiResponse } from '@@core/utils/types'; +import { DesunifyReturnType } from '@@core/utils/types/desunify.input'; +import { OriginalContactOutput } from '@@core/utils/types/original/original.crm'; +import { Injectable } from '@nestjs/common'; +import { TicketingObject } from '@ticketing/@utils/@types'; +import { IContactService } from '@ticketing/contact/types'; + +@Injectable() +export class ZendeskContactService implements IContactService { + constructor( + private prisma: PrismaService, + private logger: LoggerService, + private cryptoService: EncryptionService, + private env: EnvironmentService, + ) { + this.logger.setContext( + TicketingObject.contact.toUpperCase() + ':' + ZendeskContactService.name, + ); + } + addContact( + contactData: DesunifyReturnType, + linkedUserId: string, + ): Promise> { + throw new Error('Method not implemented.'); + } + syncContacts( + linkedUserId: string, + custom_properties?: string[], + ): Promise> { + throw new Error('Method not implemented.'); + } +} diff --git a/packages/api/src/ticketing/contact/sync/sync.service.ts b/packages/api/src/ticketing/contact/sync/sync.service.ts index a48dde21e..c668bee33 100644 --- a/packages/api/src/ticketing/contact/sync/sync.service.ts +++ b/packages/api/src/ticketing/contact/sync/sync.service.ts @@ -6,12 +6,12 @@ import { Cron } from '@nestjs/schedule'; import { ApiResponse, TICKETING_PROVIDERS } from '@@core/utils/types'; import { v4 as uuidv4 } from 'uuid'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { WebhookService } from '@@core/webhook/webhook.service'; import { UnifiedContactOutput } from '../types/model.unified'; import { IContactService } from '../types'; +import { ContactServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncContactsService implements OnModuleInit { @@ -20,7 +20,7 @@ export class SyncContactsService implements OnModuleInit { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: ContactServiceRegistry, ) { this.logger.setContext(SyncContactsService.name); } diff --git a/packages/api/src/ticketing/ticket/services/registry.service.ts b/packages/api/src/ticketing/ticket/services/registry.service.ts new file mode 100644 index 000000000..e04d37fde --- /dev/null +++ b/packages/api/src/ticketing/ticket/services/registry.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { ITicketService } from '../types'; +import { ZendeskTicketService } from './zendesk'; + +@Injectable() +export class TicketServiceRegistry { + private serviceMap: Map; + + constructor(zendesk: ZendeskTicketService) { + //TODO + this.serviceMap = new Map(); + this.serviceMap.set('zendesk_t', zendesk); + } + + getService(integrationId: string): ITicketService { + const service = this.serviceMap.get(integrationId); + if (!service) { + throw new Error(`Service not found for integration ID: ${integrationId}`); + } + return service; + } +} diff --git a/packages/api/src/ticketing/ticket/services/ticket.service.ts b/packages/api/src/ticketing/ticket/services/ticket.service.ts index fbe3befb5..1dcb6ab33 100644 --- a/packages/api/src/ticketing/ticket/services/ticket.service.ts +++ b/packages/api/src/ticketing/ticket/services/ticket.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@nestjs/common'; import { PrismaService } from '@@core/prisma/prisma.service'; -import { ZendeskService } from './zendesk'; import { LoggerService } from '@@core/logger/logger.service'; import { v4 as uuidv4 } from 'uuid'; import { ApiResponse } from '@@core/utils/types'; @@ -14,20 +13,21 @@ import { ITicketService, TicketResponse } from '../types'; import { desunify } from '@@core/utils/unification/desunify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { normalizeComments } from '../utils'; import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing'; +import { TicketServiceRegistry } from './registry.service'; +import { ZendeskTicketService } from './zendesk'; @Injectable() export class TicketService { constructor( private prisma: PrismaService, - private zendesk: ZendeskService, + private zendesk: ZendeskTicketService, private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: TicketServiceRegistry, ) { this.logger.setContext(TicketService.name); } diff --git a/packages/api/src/ticketing/ticket/services/zendesk/index.ts b/packages/api/src/ticketing/ticket/services/zendesk/index.ts index 0f236e29f..1dcd8b57a 100644 --- a/packages/api/src/ticketing/ticket/services/zendesk/index.ts +++ b/packages/api/src/ticketing/ticket/services/zendesk/index.ts @@ -12,7 +12,7 @@ import { EnvironmentService } from '@@core/environment/environment.service'; import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing'; @Injectable() -export class ZendeskService implements ITicketService { +export class ZendeskTicketService implements ITicketService { constructor( private prisma: PrismaService, private logger: LoggerService, @@ -20,7 +20,7 @@ export class ZendeskService implements ITicketService { private env: EnvironmentService, ) { this.logger.setContext( - TicketingObject.ticket.toUpperCase() + ':' + ZendeskService.name, + TicketingObject.ticket.toUpperCase() + ':' + ZendeskTicketService.name, ); } async addTicket( diff --git a/packages/api/src/ticketing/ticket/sync/sync.service.ts b/packages/api/src/ticketing/ticket/sync/sync.service.ts index 57a80a40c..2288f7a04 100644 --- a/packages/api/src/ticketing/ticket/sync/sync.service.ts +++ b/packages/api/src/ticketing/ticket/sync/sync.service.ts @@ -6,7 +6,6 @@ import { Cron } from '@nestjs/schedule'; import { ApiResponse, TICKETING_PROVIDERS } from '@@core/utils/types'; import { v4 as uuidv4 } from 'uuid'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { UnifiedTicketOutput } from '../types/model.unified'; @@ -15,6 +14,7 @@ import { tcg_tickets as TicketingTicket } from '@prisma/client'; import { normalizeComments } from '../utils'; import { ITicketService } from '../types'; import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing'; +import { TicketServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncTicketsService implements OnModuleInit { @@ -23,7 +23,7 @@ export class SyncTicketsService implements OnModuleInit { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: TicketServiceRegistry, ) { this.logger.setContext(SyncTicketsService.name); } diff --git a/packages/api/src/ticketing/ticket/ticket.module.ts b/packages/api/src/ticketing/ticket/ticket.module.ts index d6eaf2e99..46b45789f 100644 --- a/packages/api/src/ticketing/ticket/ticket.module.ts +++ b/packages/api/src/ticketing/ticket/ticket.module.ts @@ -6,8 +6,10 @@ import { WebhookService } from '@@core/webhook/webhook.service'; import { EncryptionService } from '@@core/encryption/encryption.service'; import { LoggerService } from '@@core/logger/logger.service'; import { PrismaService } from '@@core/prisma/prisma.service'; -import { ZendeskService } from './services/zendesk'; +import { ZendeskTicketService } from './services/zendesk'; import { BullModule } from '@nestjs/bull'; +import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; +import { TicketServiceRegistry } from './services/registry.service'; @Module({ imports: [ @@ -19,11 +21,13 @@ import { BullModule } from '@nestjs/bull'; providers: [ TicketService, PrismaService, - ZendeskService, + ZendeskTicketService, LoggerService, SyncTicketsService, WebhookService, EncryptionService, + FieldMappingService, + TicketServiceRegistry, ], exports: [SyncTicketsService], }) diff --git a/packages/api/src/ticketing/ticketing.module.ts b/packages/api/src/ticketing/ticketing.module.ts index 6a5ccaa05..ee4575e4d 100644 --- a/packages/api/src/ticketing/ticketing.module.ts +++ b/packages/api/src/ticketing/ticketing.module.ts @@ -3,11 +3,24 @@ import { TicketModule } from './ticket/ticket.module'; import { CommentModule } from './comment/comment.module'; import { UserModule } from './user/user.module'; import { AttachmentModule } from './attachment/attachment.module'; +import { ContactModule } from './contact/contact.module'; @Module({ - imports: [TicketModule, CommentModule, UserModule, AttachmentModule], + imports: [ + TicketModule, + CommentModule, + UserModule, + AttachmentModule, + ContactModule, + ], providers: [], controllers: [], - exports: [TicketModule, CommentModule, UserModule, AttachmentModule], + exports: [ + TicketModule, + CommentModule, + UserModule, + AttachmentModule, + ContactModule, + ], }) export class TicketingModule {} diff --git a/packages/api/src/ticketing/user/services/registry.service.ts b/packages/api/src/ticketing/user/services/registry.service.ts new file mode 100644 index 000000000..85b7f3b85 --- /dev/null +++ b/packages/api/src/ticketing/user/services/registry.service.ts @@ -0,0 +1,22 @@ +import { Injectable } from '@nestjs/common'; +import { ZendeskUserService } from './zendesk'; +import { IUserService } from '../types'; + +@Injectable() +export class UserServiceRegistry { + private serviceMap: Map; + + constructor(zendesk: ZendeskUserService) { + //TODO + this.serviceMap = new Map(); + this.serviceMap.set('zendesk_t', zendesk); + } + + getService(integrationId: string): IUserService { + const service = this.serviceMap.get(integrationId); + if (!service) { + throw new Error(`Service not found for integration ID: ${integrationId}`); + } + return service; + } +} diff --git a/packages/api/src/ticketing/user/services/user.service.ts b/packages/api/src/ticketing/user/services/user.service.ts index 1d216ddbd..fbfa95add 100644 --- a/packages/api/src/ticketing/user/services/user.service.ts +++ b/packages/api/src/ticketing/user/services/user.service.ts @@ -10,8 +10,8 @@ import { UserResponse } from '../types'; import { desunify } from '@@core/utils/unification/desunify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; +import { UserServiceRegistry } from './registry.service'; @Injectable() export class UserService { @@ -20,7 +20,7 @@ export class UserService { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: UserServiceRegistry, ) { this.logger.setContext(UserService.name); } diff --git a/packages/api/src/ticketing/user/services/zendesk/index.ts b/packages/api/src/ticketing/user/services/zendesk/index.ts index e69de29bb..e8a723f37 100644 --- a/packages/api/src/ticketing/user/services/zendesk/index.ts +++ b/packages/api/src/ticketing/user/services/zendesk/index.ts @@ -0,0 +1,35 @@ +import { EncryptionService } from '@@core/encryption/encryption.service'; +import { EnvironmentService } from '@@core/environment/environment.service'; +import { LoggerService } from '@@core/logger/logger.service'; +import { PrismaService } from '@@core/prisma/prisma.service'; +import { ApiResponse } from '@@core/utils/types'; +import { DesunifyReturnType } from '@@core/utils/types/desunify.input'; +import { Injectable } from '@nestjs/common'; +import { TicketingObject, ZendeskUserInput } from '@ticketing/@utils/@types'; +import { IUserService } from '@ticketing/user/types'; + +@Injectable() +export class ZendeskUserService implements IUserService { + constructor( + private prisma: PrismaService, + private logger: LoggerService, + private cryptoService: EncryptionService, + private env: EnvironmentService, + ) { + this.logger.setContext( + TicketingObject.user.toUpperCase() + ':' + ZendeskUserService.name, + ); + } + addUser( + userData: DesunifyReturnType, + linkedUserId: string, + ): Promise> { + throw new Error('Method not implemented.'); + } + syncUsers( + linkedUserId: string, + custom_properties?: string[], + ): Promise> { + throw new Error('Method not implemented.'); + } +} diff --git a/packages/api/src/ticketing/user/sync/sync.service.ts b/packages/api/src/ticketing/user/sync/sync.service.ts index 8daf76a2f..60d918ec9 100644 --- a/packages/api/src/ticketing/user/sync/sync.service.ts +++ b/packages/api/src/ticketing/user/sync/sync.service.ts @@ -6,12 +6,12 @@ import { Cron } from '@nestjs/schedule'; import { ApiResponse, TICKETING_PROVIDERS } from '@@core/utils/types'; import { v4 as uuidv4 } from 'uuid'; import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; -import { ServiceRegistry } from '@ticketing/@utils/@registry/registry.service'; import { unify } from '@@core/utils/unification/unify'; import { TicketingObject } from '@ticketing/@utils/@types'; import { WebhookService } from '@@core/webhook/webhook.service'; import { UnifiedUserOutput } from '../types/model.unified'; import { IUserService } from '../types'; +import { UserServiceRegistry } from '../services/registry.service'; @Injectable() export class SyncUsersService implements OnModuleInit { @@ -20,7 +20,7 @@ export class SyncUsersService implements OnModuleInit { private logger: LoggerService, private webhook: WebhookService, private fieldMappingService: FieldMappingService, - private serviceRegistry: ServiceRegistry, + private serviceRegistry: UserServiceRegistry, ) { this.logger.setContext(SyncUsersService.name); } diff --git a/packages/api/src/ticketing/user/user.controller.ts b/packages/api/src/ticketing/user/user.controller.ts index ad8c2a6e0..46f3ff6eb 100644 --- a/packages/api/src/ticketing/user/user.controller.ts +++ b/packages/api/src/ticketing/user/user.controller.ts @@ -1,4 +1,4 @@ import { Controller } from '@nestjs/common'; -@Controller('user') +@Controller('ticketing/user') export class UserController {} diff --git a/packages/api/src/ticketing/user/user.module.ts b/packages/api/src/ticketing/user/user.module.ts index 84a4b78a6..9582df234 100644 --- a/packages/api/src/ticketing/user/user.module.ts +++ b/packages/api/src/ticketing/user/user.module.ts @@ -1,7 +1,34 @@ import { Module } from '@nestjs/common'; import { UserController } from './user.controller'; +import { BullModule } from '@nestjs/bull'; +import { UserService } from './services/user.service'; +import { UserServiceRegistry } from './services/registry.service'; +import { FieldMappingService } from '@@core/field-mapping/field-mapping.service'; +import { WebhookService } from '@@core/webhook/webhook.service'; +import { EncryptionService } from '@@core/encryption/encryption.service'; +import { PrismaService } from '@@core/prisma/prisma.service'; +import { ZendeskUserService } from './services/zendesk'; +import { LoggerService } from '@@core/logger/logger.service'; +import { SyncUsersService } from './sync/sync.service'; @Module({ + imports: [ + BullModule.registerQueue({ + name: 'webhookDelivery', + }), + ], controllers: [UserController], + providers: [ + UserService, + PrismaService, + ZendeskUserService, + LoggerService, + SyncUsersService, + WebhookService, + EncryptionService, + FieldMappingService, + UserServiceRegistry, + ], + exports: [SyncUsersService], }) export class UserModule {}