Skip to content

Commit

Permalink
✅ Ticket Health Test
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jul 17, 2024
1 parent d3dfd9e commit cfd0336
Show file tree
Hide file tree
Showing 24 changed files with 285 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export class CoreUnification {
providerName,
vertical,
customFieldMappings,
connectionId,
}: {
sourceObject: T;
targetType: TargetObject;
Expand All @@ -145,6 +146,7 @@ export class CoreUnification {
slug: string;
remote_id: string;
}[];
connectionId?: string;
}): Promise<DesunifyReturnType> {
try {
let targetType_: TargetObject;
Expand Down Expand Up @@ -212,6 +214,7 @@ export class CoreUnification {
targetType_,
providerName,
customFieldMappings,
connectionId,
});
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { Injectable } from '@nestjs/common';
import axios from 'axios';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { v4 as uuidv4 } from 'uuid';
import { EnvironmentService } from '@@core/@core-services/environment/environment.service';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { ITicketingConnectionService } from '../../types';
import { ServiceRegistry } from '../registry.service';
import { AuthStrategy, CONNECTORS_METADATA } from '@panora/shared';
import { OAuth2AuthData, providerToType } from '@panora/shared';
import { EnvironmentService } from '@@core/@core-services/environment/environment.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { ConnectionsStrategiesService } from '@@core/connections-strategies/connections-strategies.service';
import { ConnectionUtils } from '@@core/connections/@utils';
import { ApiKeyAuthGuard } from '@@core/auth/guards/api-key.guard';
import {
OAuthCallbackParams,
RefreshParams,
} from '@@core/connections/@utils/types';
import { Injectable } from '@nestjs/common';
import {
AuthStrategy,
CONNECTORS_METADATA,
OAuth2AuthData,
providerToType,
} from '@panora/shared';
import axios from 'axios';
import { v4 as uuidv4 } from 'uuid';
import { ITicketingConnectionService } from '../../types';
import { ServiceRegistry } from '../registry.service';

export type FrontOAuthResponse = {
access_token: string;
Expand Down Expand Up @@ -99,9 +102,7 @@ export class FrontConnectionService implements ITicketingConnectionService {
refresh_token: this.cryptoService.encrypt(data.refresh_token),
account_url: CONNECTORS_METADATA['ticketing']['front'].urls
.apiUrl as string,
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
),
expiration_timestamp: new Date(Number(data.expires_at) * 1000),
status: 'valid',
created_at: new Date(),
},
Expand All @@ -118,9 +119,7 @@ export class FrontConnectionService implements ITicketingConnectionService {
.apiUrl as string,
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
),
expiration_timestamp: new Date(Number(data.expires_at) * 1000),
status: 'valid',
created_at: new Date(),
projects: {
Expand Down Expand Up @@ -174,9 +173,7 @@ export class FrontConnectionService implements ITicketingConnectionService {
data: {
access_token: this.cryptoService.encrypt(data.access_token),
refresh_token: this.cryptoService.encrypt(data.refresh_token),
expiration_timestamp: new Date(
new Date().getTime() + Number(data.expires_at) * 1000,
),
expiration_timestamp: new Date(Number(data.expires_at) * 1000),
},
});
this.logger.log('OAuth credentials updated : front ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import {
GithubTicketInput,
GithubTicketOutput,
} from '@ticketing/ticket/services/github/types';
import {
HubspotTicketInput,
HubspotTicketOutput,
} from '@ticketing/ticket/services/hubspot/types';
import {
FrontUserInput,
FrontUserOutput,
Expand Down Expand Up @@ -138,7 +134,6 @@ export type OriginalTicketInput =
| ZendeskTicketInput
| FrontTicketInput
| GithubTicketInput
| HubspotTicketInput
| GorgiasTicketInput
| JiraTicketInput
| GitlabTicketInput;
Expand Down Expand Up @@ -206,7 +201,6 @@ export type OriginalTicketOutput =
| ZendeskTicketOutput
| FrontTicketOutput
| GithubTicketOutput
| HubspotTicketOutput
| GorgiasTicketOutput
| JiraTicketOutput
| GitlabTicketOutput;
Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/crm/user/services/zoho/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ export class ZohoService implements IUserService {
},
},
);
this.logger.log('USERS ZOHO ' + JSON.stringify(resp.data));
this.logger.log(`Synced zoho users !`);
return {
data: resp.data.data,
data: resp.data.users,
message: 'Zoho users retrieved',
statusCode: 200,
};
Expand Down
7 changes: 6 additions & 1 deletion packages/api/src/crm/user/services/zoho/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export class ZohoUserMapper implements IUserMapper {
remote_id: string;
}[],
): UnifiedUserOutput {
return;
return {
remote_id: user.id,
name: user.full_name,
email: user.email,
remote_data: user,
};
}
}
4 changes: 3 additions & 1 deletion packages/api/src/ticketing/@lib/@unification/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class TicketingUnificationService implements IUnification {
targetType_,
providerName,
customFieldMappings,
connectionId,
}: {
sourceObject: T;
targetType_: TicketingObject;
Expand All @@ -28,6 +29,7 @@ export class TicketingUnificationService implements IUnification {
slug: string;
remote_id: string;
}[];
connectionId?: string;
}): Promise<TicketingObjectInput> {
const mapping = this.mappersRegistry.getService(
'ticketing',
Expand All @@ -36,7 +38,7 @@ export class TicketingUnificationService implements IUnification {
);

if (mapping) {
return mapping.desunify(sourceObject, customFieldMappings);
return mapping.desunify(sourceObject, customFieldMappings, connectionId);
}

throw new Error(
Expand Down
16 changes: 16 additions & 0 deletions packages/api/src/ticketing/@lib/@utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ export class Utils {
}
}

async getRemoteIdFromTagName(name: string, connection_id: string) {
try {
const res = await this.prisma.tcg_tags.findFirst({
where: {
name: name,
id_connection: connection_id,
},
});
if (!res) return undefined;

return res.remote_id;
} catch (error) {
throw error;
}
}

async getCommentUuidFromRemoteId(remote_id: string, connection_id: string) {
try {
const res = await this.prisma.tcg_comments.findFirst({
Expand Down
26 changes: 16 additions & 10 deletions packages/api/src/ticketing/tag/services/front/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Injectable } from '@nestjs/common';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { LoggerService } from '@@core/@core-services/logger/logger.service';
import { PrismaService } from '@@core/@core-services/prisma/prisma.service';
import { EncryptionService } from '@@core/@core-services/encryption/encryption.service';
import { TicketingObject } from '@ticketing/@lib/@types';
import { ApiResponse } from '@@core/utils/types';
import { SyncParam } from '@@core/utils/types/interface';
import { Injectable } from '@nestjs/common';
import { TicketingObject } from '@ticketing/@lib/@types';
import { ITagService } from '@ticketing/tag/types';
import axios from 'axios';
import { ActionType, handle3rdPartyServiceError } from '@@core/utils/errors';
import { ServiceRegistry } from '../registry.service';
import { ITagService } from '@ticketing/tag/types';
import { FrontTagOutput } from './types';
import { SyncParam } from '@@core/utils/types/interface';

@Injectable()
export class FrontService implements ITagService {
Expand Down Expand Up @@ -37,7 +36,7 @@ export class FrontService implements ITagService {
},
});

const ticket = await this.prisma.tcg_tickets.findUnique({
/*const ticket = await this.prisma.tcg_tickets.findUnique({
where: {
id_tcg_ticket: id_ticket as string,
},
Expand All @@ -58,10 +57,17 @@ export class FrontService implements ITagService {
const conversation = resp.data._results.find(
(c) => c.id === ticket.remote_id,
);

);*/
const resp = await axios.get(`${connection.account_url}/tags`, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
connection.access_token,
)}`,
},
});
return {
data: conversation.tags,
data: resp.data._results,
message: 'Front tags retrieved',
statusCode: 200,
};
Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/ticketing/tag/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export class ZendeskTagMapper implements ITagMapper {
): UnifiedTagOutput {
const unifiedTag: UnifiedTagOutput = {
remote_id: null,
remote_data: tag as any,
name: tag,
remote_data: tag,
name: tag.name,
};

return unifiedTag;
Expand Down
4 changes: 3 additions & 1 deletion packages/api/src/ticketing/tag/services/zendesk/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export type ZendeskTagInput = null;

export type ZendeskTagOutput = string;
export type ZendeskTagOutput = {
name: string;
};
10 changes: 9 additions & 1 deletion packages/api/src/ticketing/ticket/services/front/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class FrontTicketMapper implements ITicketMapper {
slug: string;
remote_id: string;
}[],
connection_id?: string,
): Promise<FrontTicketInput> {
const body_: any = {};

Expand Down Expand Up @@ -76,7 +77,14 @@ export class FrontTicketMapper implements ITicketMapper {
}

if (source.tags) {
result.tags = source.tags as string[];
result.tags = [];
for (const tag of source.tags) {
const id = await this.utils.getRemoteIdFromTagName(
tag as string,
connection_id,
);
result.tags.push(id);
}
}

if (customFieldMappings && source.field_mappings) {
Expand Down
31 changes: 18 additions & 13 deletions packages/api/src/ticketing/ticket/services/gitlab/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import {
} from '@ticketing/ticket/types/model.unified';
import { GitlabTicketInput, GitlabTicketOutput } from './types';
import { GitlabTagOutput } from '@ticketing/tag/services/gitlab/types';
import { IngestDataService } from '@@core/@core-services/unification/ingest-data.service';

@Injectable()
export class GitlabTicketMapper implements ITicketMapper {
constructor(
private mappersRegistry: MappersRegistry,
private utils: Utils,
private coreUnificationService: CoreUnification,
private ingestService: IngestDataService,
) {
this.mappersRegistry.registerService('ticketing', 'ticket', 'gitlab', this);
}
Expand All @@ -39,7 +41,9 @@ export class GitlabTicketMapper implements ITicketMapper {
description: source.description ? source.description : null,
project_id: Number(remote_project_id),
};

if (source.due_date) {
result.due_date = source.due_date;
}
if (source.status) {
result.type = source.status === 'OPEN' ? 'opened' : 'closed';
}
Expand Down Expand Up @@ -125,24 +129,25 @@ export class GitlabTicketMapper implements ITicketMapper {
}

if (ticket.labels) {
const tags = (await this.coreUnificationService.unify<
OriginalTagOutput[]
>({
sourceObject: ticket.labels.map(
const tags = await this.ingestService.ingestData<
UnifiedTagOutput,
GitlabTagOutput
>(
ticket.labels.map(
(label) =>
({
name: label,
} as GitlabTagOutput),
),
targetType: TicketingObject.tag,
providerName: 'gitlab',
vertical: 'ticketing',
connectionId: connectionId,
customFieldMappings: [],
})) as UnifiedTagOutput[];
'gitlab',
connectionId,
'ticketing',
TicketingObject.tag,
[],
);
opts = {
...opts,
tags: tags,
tags: tags.map((tag) => tag.id_tcg_tag),
};
}

Expand All @@ -161,7 +166,7 @@ export class GitlabTicketMapper implements ITicketMapper {
remote_data: ticket,
name: ticket.title,
description: ticket.description || null,
due_date: new Date(ticket.created_at),
due_date: new Date(ticket.due_date),
field_mappings,
...opts,
};
Expand Down
Loading

0 comments on commit cfd0336

Please sign in to comment.