Skip to content

Commit

Permalink
🚑 Added a lot of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Dec 29, 2023
1 parent 6ba60aa commit 7257989
Show file tree
Hide file tree
Showing 36 changed files with 421 additions and 72 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/@core/environment/environement.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/crm/contact/contact.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -35,7 +35,7 @@ import { ServiceRegistry } from '../@utils/@registry/registry.service';
SyncContactsService,
WebhookService,
EncryptionService,
ServiceRegistry,
ContactServiceRegistry,
],
exports: [SyncContactsService],
})
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/crm/contact/services/contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, ICrmService>;
export class ContactServiceRegistry {
private serviceMap: Map<string, IContactService>;

constructor(
freshsales: FreshSalesService,
Expand All @@ -18,19 +18,19 @@ export class ServiceRegistry {
pipedrive: PipedriveService,
) {
//TODO
this.serviceMap = new Map<string, ICrmService>();
this.serviceMap = new Map<string, IContactService>();
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);
}

getService<T extends ICrmService>(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;
}
}
4 changes: 2 additions & 2 deletions packages/api/src/crm/contact/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/crm/crm.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import { DealModule } from './deal/deal.module';
imports: [ContactModule, DealModule],
providers: [],
controllers: [],
exports: [ContactModule],
exports: [ContactModule, DealModule],
})
export class CrmModule {}
21 changes: 0 additions & 21 deletions packages/api/src/ticketing/@utils/@registry/registry.service.ts

This file was deleted.

10 changes: 9 additions & 1 deletion packages/api/src/ticketing/@utils/@types/index.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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';
Expand Down
27 changes: 27 additions & 0 deletions packages/api/src/ticketing/attachment/attachment.module.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/api/src/ticketing/attachment/services/registry.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { IAttachmentService } from '../types';
import { ZendeskAttachmentService } from './zendesk';

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

constructor(zendesk: ZendeskAttachmentService) {
//TODO
this.serviceMap = new Map<string, IAttachmentService>();
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;
}
}
40 changes: 40 additions & 0 deletions packages/api/src/ticketing/attachment/services/zendesk/index.ts
Original file line number Diff line number Diff line change
@@ -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<ApiResponse<ZendeskAttachmentInput>> {
throw new Error('Method not implemented.');
}
syncAttachments(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<ZendeskAttachmentInput[]>> {
throw new Error('Method not implemented.');
}
}
4 changes: 2 additions & 2 deletions packages/api/src/ticketing/attachment/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/api/src/ticketing/comment/comment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -20,10 +22,12 @@ import { CommentService } from './services/comment.service';
CommentService,
PrismaService,
LoggerService,
ZendeskService,
ZendeskCommentService,
SyncCommentsService,
WebhookService,
EncryptionService,
FieldMappingService,
CommentServiceRegistry,
],
exports: [SyncCommentsService],
})
Expand Down
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 { 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';
Expand All @@ -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);
}
Expand Down
22 changes: 22 additions & 0 deletions packages/api/src/ticketing/comment/services/registry.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable } from '@nestjs/common';
import { ZendeskCommentService } from './zendesk';
import { ICommentService } from '../types';

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

constructor(zendesk: ZendeskCommentService) {
//TODO
this.serviceMap = new Map<string, ICommentService>();
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;
}
}
Loading

0 comments on commit 7257989

Please sign in to comment.