Skip to content

Commit d6f8cd7

Browse files
authored
Filter projects (#24)
1 parent 7e53321 commit d6f8cd7

File tree

7 files changed

+80
-3
lines changed

7 files changed

+80
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- Adds Sustainable Development Goals (SDGs) field to projects
13+
- Adds filtering to Projects on type, country
1314

1415
### Changed
1516

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ patch.estimates.retrieveEstimates({ page });
141141

142142
Projects are the ways Patch takes CO2 out of the air. They can represent reforestation, enhanced weathering, direct air carbon capture, etc. When you place an order via Patch, it is allocated to a project.
143143

144+
When fetching Projects, you can add filters to the query to narrow the result. Currently supported filters are:
145+
146+
- `country`
147+
- `type`
148+
144149
[API Reference](https://docs.usepatch.com/#/?id=projects)
145150

146151
#### Examples
@@ -153,6 +158,14 @@ patch.projects.retrieveProject(projectId);
153158
// Retrieve a list of projects
154159
const page = 1; // Pass in which page of projects you'd like
155160
patch.projects.retrieveProjects({ page });
161+
162+
// Retrieve a filtered list of projects
163+
const country = 'CA'; // Pass in the country you'd like to get projects from
164+
patch.projects.retrieveProjects({ country });
165+
166+
// Retrieve a filtered list of projects
167+
const type = 'biomass'; // Pass in the project type you'd like to filter by
168+
patch.projects.retrieveProjects({ type });
156169
```
157170

158171
### Preferences

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/api/ProjectsApi.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ export default class ProjectsApi {
7171

7272
let pathParams = {};
7373
let queryParams = {
74-
page: opts['page']
74+
page: opts['page'],
75+
76+
country: opts['country'],
77+
78+
type: opts['type']
7579
};
7680
let headerParams = {};
7781
let formParams = {};

src/model/ProjectListRequest.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* Patch API V1
3+
* The core API used to integrate with Patch's service
4+
*
5+
* Contact: [email protected]
6+
*/
7+
8+
import ApiClient from '../ApiClient';
9+
10+
class ProjectListRequest {
11+
constructor() {
12+
ProjectListRequest.initialize(this);
13+
}
14+
15+
static initialize(obj) {}
16+
17+
static constructFromObject(data, obj) {
18+
if (data) {
19+
obj = obj || new ProjectListRequest();
20+
21+
if (data.hasOwnProperty('page')) {
22+
obj['page'] = ApiClient.convertToType(data['page'], 'Number');
23+
}
24+
25+
if (data.hasOwnProperty('country')) {
26+
obj['country'] = ApiClient.convertToType(data['country'], 'String');
27+
}
28+
29+
if (data.hasOwnProperty('type')) {
30+
obj['type'] = ApiClient.convertToType(data['type'], 'String');
31+
}
32+
}
33+
return obj;
34+
}
35+
}
36+
37+
ProjectListRequest.prototype['page'] = undefined;
38+
39+
ProjectListRequest.prototype['country'] = undefined;
40+
41+
ProjectListRequest.prototype['type'] = undefined;
42+
43+
export default ProjectListRequest;

test/integration/orders.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Orders Integration', function () {
2626
expect(parseFloat(createOrderResponse.data.price_cents_usd)).to.be.closeTo(
2727
500,
2828
1
29-
)
29+
);
3030
expect(createOrderResponse.data.patch_fee_cents_usd).to.equal('0.0');
3131
expect(createOrderResponse.data.mass_g).to.equal(500000);
3232
});

test/integration/projects.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,20 @@ describe('Project Integration', function () {
1414
const projectResponse = await patch.projects.retrieveProject(projectId);
1515
expect(projectResponse.data.id).to.equal(projectId);
1616
});
17+
18+
it('supports fetching all projects from the United States', async function () {
19+
const country = 'US';
20+
const { data } = await patch.projects.retrieveProjects({ country });
21+
data.map((project) => {
22+
expect(project.country).to.equal(country);
23+
});
24+
});
25+
26+
it('supports fetching all biomass projects', async function () {
27+
const type = 'biomass';
28+
const { data } = await patch.projects.retrieveProjects({ type });
29+
data.map((project) => {
30+
expect(project.type).to.equal(type);
31+
});
32+
});
1733
});

0 commit comments

Comments
 (0)