Skip to content

Commit 8992a6a

Browse files
authored
Jobber - Search & Filter Quotes (#17263)
* new components * pnpm-lock.yaml * fix page size * remove console.log * updates
1 parent 62c7aef commit 8992a6a

File tree

8 files changed

+249
-7
lines changed

8 files changed

+249
-7
lines changed

components/jobber/actions/create-client/create-client.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "jobber-create-client",
66
name: "Create Client",
77
description: "Generates a new client within Jobber. [See the documentation](https://developer.getjobber.com/docs)",
8-
version: "0.0.2",
8+
version: "0.0.3",
99
type: "action",
1010
props: {
1111
jobber,

components/jobber/actions/create-quote/create-quote.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
key: "jobber-create-quote",
55
name: "Create Quote",
66
description: "Generates a new quote for a client's property in Jobber. [See the documentation](https://developer.getjobber.com/docs/)",
7-
version: "0.0.2",
7+
version: "0.0.3",
88
type: "action",
99
props: {
1010
jobber,

components/jobber/actions/create-request/create-request.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default {
66
key: "jobber-create-request",
77
name: "Create Service Request",
88
description: "Creates a new service request for a client's first property within Jobber. [See the documentation](https://developer.getjobber.com/docs/)",
9-
version: "0.0.2",
9+
version: "0.0.3",
1010
type: "action",
1111
props: {
1212
jobber,
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import jobber from "../../jobber.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "jobber-filter-quotes",
6+
name: "Filter Quotes",
7+
description: "Filter quotes by status, quote number, or cost in Jobber. [See the documentation](https://developer.getjobber.com/docs)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
jobber,
12+
status: {
13+
type: "string",
14+
label: "Status",
15+
description: "The status to filter quotes by",
16+
options: [
17+
"draft",
18+
"awaiting_response",
19+
"archived",
20+
"approved",
21+
"converted",
22+
"changes_requested",
23+
],
24+
optional: true,
25+
},
26+
clientId: {
27+
propDefinition: [
28+
jobber,
29+
"clientId",
30+
],
31+
description: "The client ID to filter quotes by",
32+
optional: true,
33+
},
34+
quoteNumber: {
35+
type: "string",
36+
label: "Quote Number",
37+
description: "The quote number to filter quotes by",
38+
optional: true,
39+
},
40+
cost: {
41+
type: "string",
42+
label: "Cost",
43+
description: "The cost to filter quotes by",
44+
optional: true,
45+
},
46+
maxResults: {
47+
type: "integer",
48+
label: "Max Results",
49+
description: "The maximum number of results to return",
50+
default: 100,
51+
optional: true,
52+
},
53+
},
54+
async run({ $ }) {
55+
const query = `query FilterQuotes($first: Int, $after: String, $filter: QuoteFilterAttributes) {
56+
quotes(first: $first, after: $after, filter: $filter) {
57+
nodes {
58+
${constants.QUOTE_FIELDS}
59+
}
60+
pageInfo {
61+
endCursor
62+
hasNextPage
63+
}
64+
}
65+
}`;
66+
67+
const args = {
68+
filter: {
69+
status: this.status,
70+
clientId: this.clientId,
71+
quoteNumber: this.quoteNumber
72+
? {
73+
eq: +this.quoteNumber,
74+
}
75+
: undefined,
76+
cost: this.cost
77+
? {
78+
eq: +this.cost,
79+
}
80+
: undefined,
81+
},
82+
};
83+
const quotes = await this.jobber.getPaginatedResources({
84+
query,
85+
args,
86+
resourceKey: "quotes",
87+
max: this.maxResults,
88+
});
89+
$.export("$summary", `Successfully found ${quotes.length} quote${quotes.length === 1
90+
? ""
91+
: "s"}`);
92+
return quotes;
93+
},
94+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import jobber from "../../jobber.app.mjs";
2+
import constants from "../../common/constants.mjs";
3+
4+
export default {
5+
key: "jobber-search-quotes",
6+
name: "Search Quotes",
7+
description: "Search for quotes using a search termin Jobber. [See the documentation](https://developer.getjobber.com/docs)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
jobber,
12+
searchTerm: {
13+
type: "string",
14+
label: "Search Term",
15+
description: "The search term to use to filter quotes",
16+
optional: true,
17+
},
18+
maxResults: {
19+
type: "integer",
20+
label: "Max Results",
21+
description: "The maximum number of results to return",
22+
default: 100,
23+
optional: true,
24+
},
25+
},
26+
async run({ $ }) {
27+
const query = `query SearchQuotes($first: Int, $after: String, $searchTerm: String) {
28+
quotes(first: $first, after: $after, searchTerm: $searchTerm) {
29+
nodes {
30+
${constants.QUOTE_FIELDS}
31+
}
32+
pageInfo {
33+
endCursor
34+
hasNextPage
35+
}
36+
}
37+
}`;
38+
39+
const args = {
40+
searchTerm: this.searchTerm,
41+
};
42+
const quotes = await this.jobber.getPaginatedResources({
43+
query,
44+
args,
45+
resourceKey: "quotes",
46+
max: this.maxResults,
47+
});
48+
$.export("$summary", `Successfully found ${quotes.length} quote${quotes.length === 1
49+
? ""
50+
: "s"}`);
51+
return quotes;
52+
},
53+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const QUOTE_FIELDS = `
2+
id
3+
title
4+
amounts {
5+
total
6+
}
7+
client {
8+
id
9+
name
10+
}
11+
clientHubUri
12+
clientHubViewedAt
13+
contractDisclaimer
14+
createdAt
15+
depositAmountUnallocated
16+
jobberWebUri
17+
jobs {
18+
nodes {
19+
id
20+
title
21+
}
22+
}
23+
lineItems {
24+
nodes {
25+
id
26+
category
27+
name
28+
quantity
29+
totalPrice
30+
}
31+
}
32+
message
33+
quoteNumber
34+
quoteStatus
35+
salesperson {
36+
id
37+
}
38+
transitionedAt
39+
updatedAt
40+
`;
41+
42+
export default {
43+
QUOTE_FIELDS,
44+
};

components/jobber/jobber.app.mjs

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { axios } from "@pipedream/platform";
1+
import {
2+
axios, ConfigurationError,
3+
} from "@pipedream/platform";
24

35
export default {
46
type: "app",
@@ -66,20 +68,25 @@ export default {
6668
_baseUrl() {
6769
return "https://api.getjobber.com/api";
6870
},
69-
_makeRequest(opts = {}) {
71+
async _makeRequest(opts = {}) {
7072
const {
7173
$ = this,
7274
path,
7375
...otherOpts
7476
} = opts;
75-
return axios($, {
77+
const response = await axios($, {
7678
...otherOpts,
7779
url: `${this._baseUrl()}${path}`,
7880
headers: {
7981
"Authorization": `Bearer ${this.$auth.oauth_access_token}`,
8082
"X-JOBBER-GRAPHQL-VERSION": "2025-01-20",
8183
},
8284
});
85+
if (response.errors) {
86+
console.log(JSON.stringify(response, null, 2));
87+
throw new ConfigurationError(response.errors[0].message);
88+
}
89+
return response;
8390
},
8491
post(opts = {}) {
8592
return this._makeRequest({
@@ -88,5 +95,49 @@ export default {
8895
...opts,
8996
});
9097
},
98+
async *paginate({
99+
query,
100+
args = {},
101+
resourceKey,
102+
max,
103+
}) {
104+
let counter = 0;
105+
let hasNextPage;
106+
let endCursor;
107+
do {
108+
const variables = {
109+
after: endCursor,
110+
first: 10,
111+
...args,
112+
};
113+
const { data } = await this.post({
114+
data: {
115+
query,
116+
variables,
117+
},
118+
});
119+
const {
120+
nodes, pageInfo,
121+
} = data[resourceKey];
122+
if (!nodes?.length) {
123+
return;
124+
}
125+
for (const node of nodes) {
126+
counter += 1;
127+
yield node;
128+
}
129+
({
130+
hasNextPage, endCursor,
131+
} = pageInfo);
132+
} while (hasNextPage && counter < max);
133+
},
134+
async getPaginatedResources(args) {
135+
const results = [];
136+
const resources = this.paginate(args);
137+
for await (const resource of resources) {
138+
results.push(resource);
139+
}
140+
return results;
141+
},
91142
},
92143
};

components/jobber/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/jobber",
3-
"version": "0.1.1",
3+
"version": "0.2.1",
44
"description": "Pipedream Jobber Components",
55
"main": "jobber.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)