Skip to content

Commit

Permalink
Merge pull request #154 from panoratech/feat/fix-providers
Browse files Browse the repository at this point in the history
Feat/fix providers
  • Loading branch information
naelob authored Dec 12, 2023
2 parents 652bff4 + 69b7083 commit c415930
Show file tree
Hide file tree
Showing 15 changed files with 7,622 additions and 14,491 deletions.
2 changes: 1 addition & 1 deletion apps/frontend-snippet/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const providersConfig: ProvidersConfig = {
},
'zoho': {
clientId: '1000.CWBWAO0XK6QNROXMA2Y0RUZYMGJIGT',
scopes: 'AaaServer.profile.Read', //todo
scopes: 'ZohoCRM.modules.ALL',
authBaseUrl: 'https://accounts.zoho.eu/oauth/v2/auth',
logoPath: 'assets/crm/zoho_logo.png',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class ZohoConnectionService {
redirect_uri: REDIRECT_URI,
code: code,
});
//no refresh token
const domain = ZOHOLocations[zohoLocation];
const res = await axios.post(
`${domain}/oauth/v2/token`,
Expand Down Expand Up @@ -105,14 +106,14 @@ export class ZohoConnectionService {
) {
try {
const REDIRECT_URI = `${config.OAUTH_REDIRECT_BASE}/connections/oauth/callback`;

const formData = new URLSearchParams({
grant_type: 'refresh_token',
client_id: config.HUBSPOT_CLIENT_ID,
client_secret: config.HUBSPOT_CLIENT_SECRET,
client_id: config.ZOHOCRM_CLIENT_ID,
client_secret: config.ZOHOCRM_CLIENT_SECRET,
redirect_uri: REDIRECT_URI,
refresh_token: decrypt(refresh_token),
});

const res = await axios.post(
`${domain}/oauth/v2/token`,
formData.toString(),
Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/@core/prisma/prisma.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { PrismaClient } from '@prisma/client';
@Injectable()
export class PrismaService extends PrismaClient implements OnModuleInit {
async onModuleInit() {
await this.$connect();
try {
await this.$connect();
} catch (error) {
throw new Error(error);
}
}
}
3 changes: 3 additions & 0 deletions packages/api/src/crm/contact/services/hubspot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class HubspotService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'hubspot',
},
});
const dataBody = {
Expand Down Expand Up @@ -59,6 +60,7 @@ export class HubspotService {
}
return;
}

async getContacts(
linkedUserId: string,
custom_properties?: string[],
Expand All @@ -68,6 +70,7 @@ export class HubspotService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'hubspot',
},
});

Expand Down
7 changes: 5 additions & 2 deletions packages/api/src/crm/contact/services/pipedrive/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class PipedriveService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'pipedrive',
},
});
const resp = await axios.post(
Expand All @@ -41,7 +42,7 @@ export class PipedriveService {
},
);
return {
data: resp.data,
data: resp.data.data,
message: 'Pipedrive contact created',
statusCode: 201,
};
Expand All @@ -65,6 +66,7 @@ export class PipedriveService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'pipedrive',
},
});
const resp = await axios.get(`https://api.pipedrive.com/v1/persons`, {
Expand All @@ -73,8 +75,9 @@ export class PipedriveService {
Authorization: `Bearer ${decrypt(connection.access_token)}`,
},
});

return {
data: resp.data,
data: resp.data.data,
message: 'Pipedrive contacts retrieved',
statusCode: 200,
};
Expand Down
10 changes: 4 additions & 6 deletions packages/api/src/crm/contact/services/pipedrive/mappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@ export function mapToContact_Pipedrive(

// Convert to Pipedrive format if needed
const emailObject = primaryEmail
? [{ value: primaryEmail, primary: true }]
? [{ value: primaryEmail, primary: true, label: '' }]
: [];
const phoneObject = primaryPhone
? [{ value: primaryPhone, primary: true }]
? [{ value: primaryPhone, primary: true, label: '' }]
: [];

return {
name: `${source.first_name} ${source.last_name}`,
email: emailObject,
phone: phoneObject,
// Map other optional fields as needed
// label, visible_to, marketing_status, add_time, etc.
};
}

Expand All @@ -47,11 +45,11 @@ function _mapSinglePipedriveContact(
last_name: contact.last_name,
email_addresses: contact.email.map((e) => ({
email_address: e.value,
email_address_type: e.label,
email_address_type: e.label ? e.label : '',
})), // Map each email
phone_numbers: contact.phone.map((p) => ({
phone_number: p.value,
phone_type: p.label,
phone_type: p.label ? p.label : '',
})), // Map each phone number
};
}
153 changes: 67 additions & 86 deletions packages/api/src/crm/contact/services/pipedrive/types.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,78 @@
export interface PipedriveContactInput {
name: string;
owner_id?: number;
org_id?: number;
email: string | EmailObject[];
phone: string | PhoneObject[];
label?: number;
visible_to?: VisibleTo;
marketing_status?: MarketingStatus;
add_time?: string;
}

export interface PipedriveContactOutput {
id: number;
export interface PipedriveContact {
id: string;
company_id: number;
owner_id: User;
org_id: OrgId;
owner_id: {
id: number;
name: string;
email: string;
has_pic: number;
pic_hash: string;
active_flag: boolean;
value: number;
};
org_id: {
name: string;
people_count: number;
owner_id: number;
address: string;
active_flag: boolean;
cc_email: string;
value: number;
};
name: string;
first_name: string;
last_name: string;
// ... other properties
phone: Phone[];
email: Email[];
open_deals_count: number;
related_open_deals_count: number;
closed_deals_count: number;
related_closed_deals_count: number;
participant_open_deals_count: number;
participant_closed_deals_count: number;
email_messages_count: number;
activities_count: number;
done_activities_count: number;
undone_activities_count: number;
files_count: number;
notes_count: number;
followers_count: number;
won_deals_count: number;
related_won_deals_count: number;
lost_deals_count: number;
related_lost_deals_count: number;
active_flag: boolean;
phone: { value: string; primary: boolean; label: string }[];
email: { value: string; primary: boolean; label: string }[];
primary_email: string;
// ... other properties
picture_id: PictureId;
// ... other properties
first_char: string;
update_time: Date;
add_time: Date;
visible_to: string;
marketing_status: string;
picture_id: {
item_type: string;
item_id: number;
active_flag: boolean;
add_time: string;
update_time: string;
added_by_user_id: number;
pictures: {
'128': string;
'512': string;
};
value: number;
};
next_activity_date: string;
next_activity_time: string;
next_activity_id: number;
last_activity_id: number;
last_activity_date: string;
last_incoming_mail_time: string;
last_outgoing_mail_time: string;
label: number;
org_name: string;
owner_name: string;
cc_email: string;
}

interface User {
id: number;
name: string;
email: string;
has_pic: number;
pic_hash: string;
active_flag: boolean;
}

interface OrgId {
name: string;
people_count: number;
owner_id: number;
address: string;
active_flag: boolean;
cc_email: string;
value: number;
}

//OUTPUT
interface Phone {
value: string;
primary: boolean;
label: string;
}

//OUTPUT
interface Email {
value: string;
primary: boolean;
label: string;
}

//OUTPUT
interface PictureId {
item_type: string;
item_id: number;
active_flag: boolean;
add_time: string;
update_time: string;
added_by_user_id: number;
pictures: Record<string, string>;
value: number;
}

//INPUT
interface EmailObject {
value: string;
primary?: boolean;
label?: string;
}

//INPUT
type PhoneObject = EmailObject;

//INPUT
type MarketingStatus =
| 'no_consent'
| 'unsubscribed'
| 'subscribed'
| 'archived';

//INPUT
type VisibleTo = 1 | 3 | 5 | 7;
export type PipedriveContactInput = Partial<PipedriveContact>;
export type PipedriveContactOutput = PipedriveContactInput;
14 changes: 11 additions & 3 deletions packages/api/src/crm/contact/services/zendesk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,24 @@ export class ZendeskService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'zendesk',
},
});
const resp = await axios.post(
`https://api.getbase.com/v2/contacts`,
JSON.stringify(contactData),
{
data: contactData,
},
{
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${decrypt(connection.access_token)}`,
},
},
);

return {
data: resp.data,
data: resp.data.data,
message: 'Zendesk contact created',
statusCode: 201,
};
Expand All @@ -64,6 +68,7 @@ export class ZendeskService {
const connection = await this.prisma.connections.findFirst({
where: {
id_linked_user: linkedUserId,
provider_slug: 'zendesk',
},
});
const resp = await axios.get(`https://api.getbase.com/v2/contacts`, {
Expand All @@ -72,8 +77,11 @@ export class ZendeskService {
Authorization: `Bearer ${decrypt(connection.access_token)}`,
},
});
const finalData = resp.data.items.map((item) => {
return item.data;
});
return {
data: resp.data,
data: finalData,
message: 'Zendesk contacts retrieved',
statusCode: 200,
};
Expand Down
Loading

0 comments on commit c415930

Please sign in to comment.