Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the posibility to send fields to the select #1

Merged
merged 1 commit into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
coverage/
.nyc_output/
2 changes: 1 addition & 1 deletion .nycrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"exclude": [
"coverages/",
"coverage/",
"tests/",
"mocks/",
".eslintrc.js",
Expand Down
9 changes: 7 additions & 2 deletions lib/api-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,16 @@ class ApiGet extends API {
id: this.recordId
};

const record = await this.model.get({
const getParams = {
filters: this._parseFilters ? this._parseFilters(filters) : filters,
page: 1,
limit: 1
});
};

if(this.fieldsToSelect)
getParams.fields = this.fieldsToSelect;

const record = await this.model.get(getParams);

if(!record.length) {
return this
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/api-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,41 @@ describe('ApiGet', () => {
limit: 1
});
});

it('Should pass fields to select if the getter is defined', async () => {

const getFake = sandbox.fake.returns([]);
const getTotalsFake = sandbox.fake.returns({ total: 0 });

const getModelInstanceFake = sandbox.stub(ApiGet.prototype, '_getModelInstance');
getModelInstanceFake.returns({
get: getFake,
getTotals: getTotalsFake
});

class MyApiGet extends ApiGet {
get fieldsToSelect() {
return ['id', 'name', 'status'];
}
}

const apiGet = new MyApiGet();
apiGet.endpoint = '/some-parent/1';
apiGet.data = {};
apiGet.headers = {};

await apiGet.validate();

await apiGet.process();

sandbox.assert.calledOnce(getFake);
sandbox.assert.calledWithExactly(getFake, {
filters: { id: '1' },
page: 1,
limit: 1,
fields: ['id', 'name', 'status']
});
});
});

});