Skip to content

Commit

Permalink
Return opportunityId for opportunityLineItem even during incremental …
Browse files Browse the repository at this point in the history
…syncs
  • Loading branch information
ebouck committed Nov 22, 2024
1 parent c4a1829 commit d8bf8c0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/old-onions-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@runlightyear/hubspot": minor
---

Return opportunityId for opportunityLineItem even during incremental syncs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export class OpportunityLineItemSynchronizer extends HubSpotModelSynchronizer {
price: "properties.price",
productId: "properties.hs_product_id",
opportunityId: (source: any) => {
return source.associations.deals.results[0].id;
if (
"associations" in source &&
"deals" in source.associations &&
"results" in source.associations.deals &&
source.associations.deals.results.length > 0
) {
return source.associations.deals.results[0].id;
}

return undefined;
},
};
}
Expand All @@ -32,4 +41,24 @@ export class OpportunityLineItemSynchronizer extends HubSpotModelSynchronizer {
deal_id: "opportunityId",
};
}

async list(props: {
syncType: "FULL" | "INCREMENTAL";
lastUpdatedAt?: string;
cursor?: string;
}): Promise<{ cursor: any; objects: any[] }> {
const superList = await super.list(props);

// associations aren't returned in incremental syncs, so we have to do gets for each object
if (props.syncType === "INCREMENTAL") {
const newObjects = [];
for (const object of superList.objects) {
const newObject = await this.get(object.id);
newObjects.push(newObject);
}
return { ...superList, objects: newObjects };
}

return superList;
}
}

0 comments on commit d8bf8c0

Please sign in to comment.