Skip to content

Commit

Permalink
🚧 Added zendesk and front mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
naelob committed Jan 6, 2024
1 parent 371bced commit e0b1829
Show file tree
Hide file tree
Showing 13 changed files with 245 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 { UnifiedAccountOutput } from '../types/model.unified';
import { AccountResponse } from '../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/ticketing/account/services/front/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class FrontService implements IAccountService {
},
});

const resp = await axios.get('https://api2.frontapp.com/teammates', {
const resp = await axios.get('https://api2.frontapp.com/accounts', {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
Expand Down
20 changes: 15 additions & 5 deletions packages/api/src/ticketing/account/services/front/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ export class FrontAccountMapper implements IAccountMapper {
// If the source is not an array, convert it to an array for mapping
const sourcesArray = Array.isArray(source) ? source : [source];

return sourcesArray.map((ticket) =>
this.mapSingleTicketToUnified(ticket, customFieldMappings),
return sourcesArray.map((account) =>
this.mapSingleAccountToUnified(account, customFieldMappings),
);
}

private mapSingleTicketToUnified(
ticket: FrontAccountOutput,
private mapSingleAccountToUnified(
account: FrontAccountOutput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedAccountOutput {
return;
const field_mappings = customFieldMappings?.map((mapping) => ({
[mapping.slug]: account.custom_fields?.[mapping.remote_id],
}));

const unifiedAccount: UnifiedAccountOutput = {
name: account.name,
domains: account.domains.flat(),
field_mappings: field_mappings,
};

return unifiedAccount;
}
}
21 changes: 20 additions & 1 deletion packages/api/src/ticketing/account/services/front/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,23 @@ export type FrontAccountInput = {
id: string;
};

export type FrontAccountOutput = FrontAccountInput;
export type FrontAccountOutput = {
_links: {
self: string;
related: {
contacts: string;
};
};
id: string;
name: string;
logo_url: string;
description: string;
domains: string[][];
external_id: number;
custom_fields: {
employees: number;
headquarters: string;
};
created_at: number;
updated_at: number;
};
27 changes: 22 additions & 5 deletions packages/api/src/ticketing/contact/services/front/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,35 @@ export class FrontContactMapper implements IContactMapper {
// If the source is not an array, convert it to an array for mapping
const sourcesArray = Array.isArray(source) ? source : [source];

return sourcesArray.map((ticket) =>
this.mapSingleTicketToUnified(ticket, customFieldMappings),
return sourcesArray.map((contact) =>
this.mapSingleContactToUnified(contact, customFieldMappings),
);
}

private mapSingleTicketToUnified(
ticket: FrontContactOutput,
private mapSingleContactToUnified(
contact: FrontContactOutput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedContactOutput {
return;
const field_mappings = customFieldMappings?.map((mapping) => ({
[mapping.slug]: contact.custom_fields?.[mapping.remote_id],
}));
const emailHandle = contact.handles.find(
(handle) => handle.source === 'email',
);
const phoneHandle = contact.handles.find(
(handle) => handle.source === 'phone',
);

const unifiedContact: UnifiedContactOutput = {
name: contact.name,
email_address: emailHandle.handle || '',
phone_number: phoneHandle.handle || '',
field_mappings: field_mappings,
};

return unifiedContact;
}
}
37 changes: 36 additions & 1 deletion packages/api/src/ticketing/contact/services/front/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,39 @@ export type FrontContactInput = {
id: string;
};

export type FrontContactOutput = FrontContactInput;
export type FrontContactOutput = {
_links: ContactLink;
id: string;
name: string;
description: string;
avatar_url: string;
is_spammer: boolean;
links: string[][];
groups: Group[];
handles: Handle[];
custom_fields: {
[key: string]: string | boolean;
};
is_private: boolean;
};

type ContactLink = {
self: string;
related: {
notes?: string;
conversations?: string;
owner?: string | null;
};
};

type Group = {
_links: ContactLink;
id: string;
name: string;
is_private: boolean;
};

type Handle = {
handle: string;
source: string;
};
2 changes: 1 addition & 1 deletion packages/api/src/ticketing/team/services/front/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class FrontService implements ITeamService {
},
});

const resp = await axios.get('https://api2.frontapp.com/teammates', {
const resp = await axios.get('https://api2.frontapp.com/teams', {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${this.cryptoService.decrypt(
Expand Down
14 changes: 9 additions & 5 deletions packages/api/src/ticketing/team/services/front/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@ export class FrontTeamMapper implements ITeamMapper {
// If the source is not an array, convert it to an array for mapping
const sourcesArray = Array.isArray(source) ? source : [source];

return sourcesArray.map((ticket) =>
this.mapSingleTicketToUnified(ticket, customFieldMappings),
return sourcesArray.map((team) =>
this.mapSingleTeamToUnified(team, customFieldMappings),
);
}

private mapSingleTicketToUnified(
ticket: FrontTeamOutput,
private mapSingleTeamToUnified(
team: FrontTeamOutput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedTeamOutput {
return;
const unifiedTeam: UnifiedTeamOutput = {
name: team.name,
};

return unifiedTeam;
}
}
43 changes: 42 additions & 1 deletion packages/api/src/ticketing/team/services/front/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,45 @@ export type FrontTeamInput = {
id: string;
};

export type FrontTeamOutput = FrontTeamInput;
export type FrontTeamOutput = {
_links: TeamLink;
id: string;
name: string;
inboxes: Inbox[];
members: TeamMember[];
};

type TeamLink = {
self: string;
related?: {
teammates?: string;
conversations?: string;
channels?: string;
owner?: string;
};
};

type CustomFields = {
[key: string]: string | boolean | number | null;
};

type Inbox = {
_links: TeamLink;
id: string;
name: string;
is_private: boolean;
custom_fields: CustomFields;
};

type TeamMember = {
_links: TeamLink;
id: string;
email: string;
username: string;
first_name: string;
last_name: string;
is_admin: boolean;
is_available: boolean;
is_blocked: boolean;
custom_fields: CustomFields;
};
20 changes: 15 additions & 5 deletions packages/api/src/ticketing/user/services/front/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ export class FrontUserMapper implements IUserMapper {
// If the source is not an array, convert it to an array for mapping
const sourcesArray = Array.isArray(source) ? source : [source];

return sourcesArray.map((ticket) =>
this.mapSingleTicketToUnified(ticket, customFieldMappings),
return sourcesArray.map((user) =>
this.mapSingleUserToUnified(user, customFieldMappings),
);
}

private mapSingleTicketToUnified(
ticket: FrontUserOutput,
private mapSingleUserToUnified(
user: FrontUserOutput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedUserOutput {
return;
const field_mappings = customFieldMappings?.map((mapping) => ({
[mapping.slug]: user.custom_fields?.[mapping.remote_id],
}));

const unifiedUser: UnifiedUserOutput = {
name: `${user.last_name} ${user.last_name}`,
email_address: user.email,
field_mappings: field_mappings,
};

return unifiedUser;
}
}
25 changes: 24 additions & 1 deletion packages/api/src/ticketing/user/services/front/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,27 @@ export type FrontUserInput = {
id: string;
};

export type FrontUserOutput = FrontUserInput;
export type FrontUserOutput = {
_links: TeammateLink;
id: string;
email: string;
username: string;
first_name: string;
last_name: string;
is_admin: boolean;
is_available: boolean;
is_blocked: boolean;
custom_fields: CustomFields;
};

type TeammateLink = {
self: string;
related: {
inboxes: string;
conversations: string;
};
};

type CustomFields = {
[key: string]: string | boolean | number | null;
};
18 changes: 14 additions & 4 deletions packages/api/src/ticketing/user/services/zendesk/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,28 @@ export class ZendeskUserMapper implements IUserMapper {
if (!Array.isArray(source)) {
return this.mapSingleUserToUnified(source, customFieldMappings);
}
return source.map((ticket) =>
this.mapSingleUserToUnified(ticket, customFieldMappings),
return source.map((user) =>
this.mapSingleUserToUnified(user, customFieldMappings),
);
}

private mapSingleUserToUnified(
ticket: ZendeskUserOutput,
user: ZendeskUserOutput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): UnifiedUserOutput {
return;
const field_mappings = customFieldMappings?.map((mapping) => ({
[mapping.slug]: user.user_fields?.[mapping.remote_id],
}));

const unifiedUser: UnifiedUserOutput = {
name: user.name,
email_address: user.email,
field_mappings: field_mappings,
};

return unifiedUser;
}
}
49 changes: 46 additions & 3 deletions packages/api/src/ticketing/user/services/zendesk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@ export type ZendeskUserInput = {
_: string;
};

export type ZendeskUserOutput = ZendeskUserInput & {
id: number; // Read-only. Automatically assigned when the ticket is created.
};
export type ZendeskUserOutput = Partial<{
active: boolean;
alias?: string;
chat_only: boolean;
created_at: string;
custom_role_id?: number;
default_group_id?: number;
details?: string;
email: string;
external_id?: string;
iana_time_zone: string;
id: number;
last_login_at: string;
locale?: string;
locale_id?: number;
moderator?: boolean;
name: string;
notes?: string;
only_private_comments?: boolean;
organization_id?: number;
phone?: string;
photo?: { [key: string]: any }; // Assuming an object type for the Attachment object
remote_photo_url?: string;
report_csv: boolean;
restricted_agent?: boolean;
role?: string;
role_type: number;
shared: boolean;
shared_agent: boolean;
shared_phone_number?: boolean;
signature?: string;
suspended?: boolean;
tags?: string[];
ticket_restriction?:
| 'organization'
| 'groups'
| 'assigned'
| 'requested'
| null;
time_zone?: string;
two_factor_auth_enabled: boolean;
updated_at: string;
url: string;
user_fields?: { [key: string]: any }; // Assuming an object type for custom fields
verified?: boolean;
}>;

0 comments on commit e0b1829

Please sign in to comment.