Skip to content

Commit

Permalink
🚧 Fixed build
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jan 3, 2024
1 parent 572158d commit 5cc8221
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 30 deletions.
15 changes: 8 additions & 7 deletions packages/api/src/crm/contact/services/hubspot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export interface HubspotContactInput {
[key: string]: any;
}

export interface HubspotContactOutput {
id: string;
properties: HubspotPropertiesOuput;
createdAt: string;
updatedAt: string;
archived: boolean;
}

type HubspotPropertiesOuput = {
createdate: string;
email: string;
Expand All @@ -35,10 +43,3 @@ export const commonHubspotProperties = {
lastname: '',
// Add any other common properties here
};
export interface HubspotContactOutput {
id: string;
properties: HubspotPropertiesOuput;
createdAt: string;
updatedAt: string;
archived: boolean;
}
6 changes: 6 additions & 0 deletions packages/api/src/ticketing/comment/comment.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { CommentController } from './comment.controller';
import { CommentService } from './services/comment.service';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ServiceRegistry } from './services/registry.service';
import { GithubService } from './services/github';
import { FrontService } from './services/front';
import { HubspotService } from './services/hubspot';

@Module({
imports: [
Expand All @@ -29,6 +32,9 @@ import { ServiceRegistry } from './services/registry.service';
ServiceRegistry,
/* PROVIDERS SERVICES */
ZendeskService,
HubspotService,
FrontService,
GithubService,
],
exports: [SyncService],
})
Expand Down
10 changes: 6 additions & 4 deletions packages/api/src/ticketing/comment/services/hubspot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class HubspotService implements ICommentService {
): Promise<ApiResponse<HubspotCommentOutput>> {
try {
//TODO: check required scope => crm.objects.contacts.write
const connection = await this.prisma.connections.findFirst({
/*const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'hubspot_t',
Expand All @@ -57,7 +57,8 @@ export class HubspotService implements ICommentService {
data: resp.data,
message: 'Hubspot comment created',
statusCode: 201,
};
};*/
return;
} catch (error) {
handleServiceError(
error,
Expand All @@ -73,7 +74,7 @@ export class HubspotService implements ICommentService {
id_ticket: string,
): Promise<ApiResponse<OriginalCommentOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
/*const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'hubspot_t',
Expand Down Expand Up @@ -106,7 +107,8 @@ export class HubspotService implements ICommentService {
data: resp.data._results,
message: 'Hubspot comments retrieved',
statusCode: 200,
};
};*/
return;
} catch (error) {
handleServiceError(
error,
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/ticketing/comment/services/zendesk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type BaseComment = {
via?: Via; // Describes how the object was created.
};

type Attachment = {
export type Attachment = {
content_type: string; // The content type of the image, e.g., "image/png".
content_url: string; // A full URL where the attachment image file can be downloaded.
deleted: boolean; // If true, the attachment has been deleted.
Expand All @@ -40,7 +40,7 @@ type Attachment = {
width: string | null; // The width of the image file in pixels, or null if unknown.
};

export type CustomField = {
export type CustomField_ = {
id: string;
value: any;
};
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/ticketing/ticket/services/front/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { ApiResponse } from '@@core/utils/types';
import axios from 'axios';
import { ActionType, handleServiceError } from '@@core/utils/errors';
import { EnvironmentService } from '@@core/environment/environment.service';
import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing';
import { ServiceRegistry } from '../registry.service';
import { FrontTicketInput, FrontTicketOutput } from './types';

Expand Down Expand Up @@ -68,7 +67,7 @@ export class FrontService implements ITicketService {
async syncTickets(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<OriginalTicketOutput[]>> {
): Promise<ApiResponse<FrontTicketOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/ticketing/ticket/services/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { ITicketService } from '@ticketing/ticket/types';
import { ApiResponse } from '@@core/utils/types';
import axios from 'axios';
import { ActionType, handleServiceError } from '@@core/utils/errors';
import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing';
import { ServiceRegistry } from '../registry.service';
import { GithubTicketInput, GithubTicketOutput } from './types';

Expand Down Expand Up @@ -66,7 +65,7 @@ export class GithubService implements ITicketService {
async syncTickets(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<OriginalTicketOutput[]>> {
): Promise<ApiResponse<GithubTicketOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
Expand Down
26 changes: 19 additions & 7 deletions packages/api/src/ticketing/ticket/services/hubspot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { ITicketService } from '@ticketing/ticket/types';
import { ApiResponse } from '@@core/utils/types';
import axios from 'axios';
import { ActionType, handleServiceError } from '@@core/utils/errors';
import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing';
import { ServiceRegistry } from '../registry.service';
import { HubspotTicketInput, HubspotTicketOutput } from './types';
import {
HubspotTicketInput,
HubspotTicketOutput,
commonHubspotProperties,
} from './types';

@Injectable()
export class HubspotService implements ITicketService {
Expand All @@ -35,9 +38,9 @@ export class HubspotService implements ITicketService {
provider_slug: 'hubspot_t',
},
});
const dataBody = ticketData;
const dataBody = { properties: ticketData };
const resp = await axios.post(
`https://api2.frontapp.com/conversations`,
`https://api.hubapi.com/crm/v3/objects/tickets`,
JSON.stringify(dataBody),
{
headers: {
Expand Down Expand Up @@ -66,7 +69,7 @@ export class HubspotService implements ITicketService {
async syncTickets(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<OriginalTicketOutput[]>> {
): Promise<ApiResponse<HubspotTicketOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
Expand All @@ -75,7 +78,16 @@ export class HubspotService implements ITicketService {
},
});

const resp = await axios.get('https://api2.frontapp.com/conversations', {
const commonPropertyNames = Object.keys(commonHubspotProperties);
const allProperties = [...commonPropertyNames, ...custom_properties];
const baseURL = 'https://api.hubapi.com/crm/v3/objects/tickets/';

const queryString = allProperties
.map((prop) => `properties=${encodeURIComponent(prop)}`)
.join('&');

const url = `${baseURL}?${queryString}`;
const resp = await axios.get(url, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
Expand All @@ -86,7 +98,7 @@ export class HubspotService implements ITicketService {
this.logger.log(`Synced hubspot tickets !`);

return {
data: resp.data._results,
data: resp.data.results,
message: 'Hubspot tickets retrieved',
statusCode: 200,
};
Expand Down
33 changes: 32 additions & 1 deletion packages/api/src/ticketing/ticket/services/hubspot/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
export type HubspotTicketInput = {
subject: string;
hs_pipeline: string;
hubspot_owner_id: string;
hs_pipeline_stage: string;
hs_ticket_priority: string;
};

export type HubspotTicketOutput = {
id: string;
properties: TicketProperties;
createdAt: string;
updatedAt: string;
archived: boolean;
};

export type HubspotTicketOutput = HubspotTicketInput;
type TicketProperties = {
createdate: string;
hs_lastmodifieddate: string;
hs_pipeline: string;
hs_pipeline_stage: string;
hs_ticket_priority: string;
hubspot_owner_id: string;
subject: string;
[key: string]: string;
};

export const commonHubspotProperties = {
createdate: '',
hs_lastmodifieddate: '',
hs_pipeline: '',
hs_pipeline_stage: '',
hs_ticket_priority: '',
hubspot_owner_id: '',
subject: '',
};
3 changes: 1 addition & 2 deletions packages/api/src/ticketing/ticket/services/zendesk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { ApiResponse } from '@@core/utils/types';
import axios from 'axios';
import { ActionType, handleServiceError } from '@@core/utils/errors';
import { EnvironmentService } from '@@core/environment/environment.service';
import { OriginalTicketOutput } from '@@core/utils/types/original/original.ticketing';
import { ServiceRegistry } from '../registry.service';

@Injectable()
Expand Down Expand Up @@ -73,7 +72,7 @@ export class ZendeskService implements ITicketService {
async syncTickets(
linkedUserId: string,
custom_properties?: string[],
): Promise<ApiResponse<OriginalTicketOutput[]>> {
): Promise<ApiResponse<ZendeskTicketOutput[]>> {
try {
const connection = await this.prisma.connections.findFirst({
where: {
Expand Down
6 changes: 6 additions & 0 deletions packages/api/src/ticketing/ticket/ticket.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { ZendeskService } from './services/zendesk';
import { BullModule } from '@nestjs/bull';
import { FieldMappingService } from '@@core/field-mapping/field-mapping.service';
import { ServiceRegistry } from './services/registry.service';
import { HubspotService } from './services/hubspot';
import { FrontService } from './services/front';
import { GithubService } from './services/github';

@Module({
imports: [
Expand All @@ -29,6 +32,9 @@ import { ServiceRegistry } from './services/registry.service';
ServiceRegistry,
/* PROVIDERS SERVICES */
ZendeskService,
HubspotService,
FrontService,
GithubService,
],
exports: [SyncService],
})
Expand Down
Loading

0 comments on commit 5cc8221

Please sign in to comment.