Skip to content

Commit

Permalink
Fixing hubspot get user code
Browse files Browse the repository at this point in the history
  • Loading branch information
davetaz committed Oct 9, 2024
1 parent 9f55d7c commit 94c0279
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
52 changes: 34 additions & 18 deletions controllers/hubspot.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,50 @@ async function getHubspotUser(userId, email) {
}
],
properties: ["email", "firstname", "lastname", "associatedcompanyid", "odi_membership__active_or_lapsed__", "odi_member_partner_type"]
}
};

const contactResponse = await hubspotClient.crm.contacts.searchApi.doSearch(contactSearchRequest);

if (!contactResponse || !contactResponse.results || contactResponse.results.length === 0) {
throw new Error("No contact found with the provided email.");
}

const companyId = contactResponse.results[0].properties.associatedcompanyid;
const hubSpotId = contactResponse.results[0].id;
let membershipStatus = contactResponse.results[0].properties.odi_membership__active_or_lapsed__;
let membershipType = contactResponse.results[0].properties.odi_member_partner_type;
let companyMembership = false;

const companySearchRequest = {
filterGroups: [
{
filters: [
// If companyId is valid, fetch company details
if (companyId) {
try {
const companySearchRequest = {
filterGroups: [
{
propertyName: "hs_object_id",
operator: "EQ",
value: companyId
filters: [
{
propertyName: "hs_object_id",
operator: "EQ",
value: companyId
}
]
}
]
],
properties: ["name", "odi_membership_status__active_or_lapsed__", "member_partner_type_org_"]
};
const companyResponse = await hubspotClient.crm.companies.searchApi.doSearch(companySearchRequest);

if (companyResponse && companyResponse.results && companyResponse.results.length > 0) {
if (companyResponse.results[0].properties.odi_membership_status__active_or_lapsed__ === "Active") {
companyMembership = true;
membershipStatus = "Active";
membershipType = companyResponse.results[0].properties.member_partner_type_org_;
}
}
],
properties: ["name", "odi_membership_status__active_or_lapsed__", "member_partner_type_org_"]
}
const companyResponse = await hubspotClient.crm.companies.searchApi.doSearch(companySearchRequest);
let companyMembership = false;
if (companyResponse.results[0].properties.odi_membership_status__active_or_lapsed__ == "Active") {
companyMembership = true;
membershipStatus = "Active";
membershipType = companyResponse.results[0].properties.member_partner_type_org_;
} catch (companyError) {
console.warn("Error fetching company details:", companyError);
// Continue without company details if there's an error fetching them
}
}

// Check if a record with the hubSpotId already exists
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "care.theodi.org",
"version": "2.8.1",
"version": "2.8.2",
"description": "The ODI Care tool (AI enabled)",
"main": "index.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion views/pages/glossary.ejs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<link href="/css/water.css" rel="stylesheet">
<link href="/css/glyphicon.css" rel="stylesheet">
<link href="/css/style.css" rel="stylesheet">
Expand Down

0 comments on commit 94c0279

Please sign in to comment.