Skip to content

Commit 4081e2e

Browse files
committed
Adjusting subsequent runs of 'new deal in stage'
1 parent 6357cd7 commit 4081e2e

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

components/hubspot/sources/new-deal-in-stage/new-deal-in-stage.mjs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,26 @@ export default {
6161
getParams() {
6262
return null;
6363
},
64-
getStageParams(stage) {
65-
const filter = {
66-
propertyName: "dealstage",
67-
operator: "EQ",
68-
value: stage,
69-
};
64+
getAllStagesParams(after) {
65+
const filters = [
66+
{
67+
propertyName: "dealstage",
68+
operator: "IN",
69+
values: this.stages,
70+
},
71+
];
72+
73+
// Add time filter for subsequent runs to only get recently modified deals
74+
if (after) {
75+
filters.push({
76+
propertyName: "hs_lastmodifieddate",
77+
operator: "GT",
78+
value: after,
79+
});
80+
}
81+
7082
const filterGroup = {
71-
filters: [
72-
filter,
73-
],
83+
filters,
7484
};
7585
return {
7686
data: {
@@ -89,8 +99,9 @@ export default {
8999
object: "deals",
90100
};
91101
},
92-
async processDeals(params, after, initialEventsEmitted) {
102+
async processDeals(params, after) {
93103
let maxTs = after || 0;
104+
let initialEventsEmitted = 0;
94105

95106
do {
96107
const results = await this.hubspot.searchCRM(params);
@@ -114,7 +125,7 @@ export default {
114125
this._setAfter(ts);
115126
}
116127
if (!after && ++initialEventsEmitted >= MAX_INITIAL_EVENTS) {
117-
return initialEventsEmitted;
128+
return;
118129
}
119130
}
120131
}
@@ -124,17 +135,10 @@ export default {
124135
break;
125136
}
126137
} while (params.after);
127-
return initialEventsEmitted;
128138
},
129139
async processResults(after) {
130-
let initialEventsEmitted = 0;
131-
for (const stage of this.stages) {
132-
const params = this.getStageParams(stage);
133-
initialEventsEmitted += await this.processDeals(params, after, initialEventsEmitted);
134-
if (initialEventsEmitted >= MAX_INITIAL_EVENTS) {
135-
return;
136-
}
137-
}
140+
const params = this.getAllStagesParams(after);
141+
await this.processDeals(params, after);
138142
},
139143
getOwner(ownerId) {
140144
return this.hubspot.makeRequest({

0 commit comments

Comments
 (0)