Skip to content

Commit

Permalink
fix(api-core): remove default after* response transformations
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The core API classes no longer apply after* transformations on the response. Previously, only the collection data was being returned when making API calls which made it difficult to react to the metadata around the response (e.g. pagination). Developers will have to unwrap the response manually.

Example response callback:

```
onResponse(response) {
  response && response.data && response.data.user|| {};
}
```
  • Loading branch information
Rob McGuinness committed Dec 19, 2017
1 parent 5b0cffa commit 6f17d3a
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 92 deletions.
6 changes: 0 additions & 6 deletions packages/api-core/src/resources/organizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ export default class AvOrganizations extends AvApi {
this.avUsers = avUsers;
}

afterQuery(response) {
return response && response.data && response.data.organizations
? response.data.organizations
: [];
}

queryOrganizations(user, config) {
const params = Object.assign({}, { userId: user.id }, config.params || {});
return this.query(Object.assign({}, { params }, config));
Expand Down
6 changes: 1 addition & 5 deletions packages/api-core/src/resources/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ export default class AvPermissions extends AvApi {
);
super(http, promise, thisConfig);
}
afterQuery(response) {
return response && response.data && response.data.permissions
? response.data.permissions
: [];
}

getPermissions(id, region) {
return this.query({
params: { id, region },
Expand Down
6 changes: 0 additions & 6 deletions packages/api-core/src/resources/providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ export default class AvProviders extends AvApi {
super(http, promise, thisConfig);
}

afterQuery(response) {
return response && response.data && response.data.providers
? response.data.providers
: [];
}

getProviders(customerId, config) {
const params = Object.assign({}, { customerId }, config.params || {});
return this.query(Object.assign({}, { params }, config));
Expand Down
6 changes: 0 additions & 6 deletions packages/api-core/src/resources/regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ export default class AvRegions extends AvApi {
this.AvUsers = AvUsers;
}

afterGet(response) {
return response && response.data && response.data.regions
? response.data.regions
: [];
}

afterUpdate(response) {
this.setPageBust();
return response;
Expand Down
13 changes: 0 additions & 13 deletions packages/api-core/src/resources/tests/organizations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ describe('AvOrganizations', () => {
}).toThrow('[avUsers] must be defined');
});

test('afterQuery() should return response.data.organizations if it exists or an empty array', () => {
api = new AvOrganizations(mockHttp, Promise, mockAvUsers);
const testResponse1 = {};
const organizations = ['testOrg'];
const testResponse2 = {
data: {
organizations,
},
};
expect(api.afterQuery(testResponse1)).toEqual([]);
expect(api.afterQuery(testResponse2)).toEqual(organizations);
});

test('queryOrganizations() should call query with user.id added to params.userId', () => {
api = new AvOrganizations(mockHttp, Promise, mockAvUsers);
api.query = jest.fn();
Expand Down
15 changes: 1 addition & 14 deletions packages/api-core/src/resources/tests/permissions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,7 @@ describe('AvPermissions', () => {
expect(api).toBeDefined();
});

test('afterQuery should return response.data.permissions if it exists or an empty array', () => {
api = new AvPermissions(mockHttp, Promise);
const testResponse1 = {};
const permissions = ['testPermission'];
const testResponse2 = {
data: {
permissions,
},
};
expect(api.afterQuery(testResponse1)).toEqual([]);
expect(api.afterQuery(testResponse2)).toEqual(permissions);
});

test('getPermissions should query with permissionId and region params from arguments', () => {
test('getPermissions() should query with permissionId and region params from arguments', () => {
api = new AvPermissions(mockHttp, Promise);
api.query = jest.fn();
const id = 'testPermissionId';
Expand Down
13 changes: 0 additions & 13 deletions packages/api-core/src/resources/tests/providers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ describe('AvProviders', () => {
expect(api).toBeDefined();
});

test('afterQuery should return response.data.providers if it exists or an empty array', () => {
api = new AvProviders(mockHttp, Promise);
const testResponse1 = {};
const providers = ['testProvider'];
const testResponse2 = {
data: {
providers,
},
};
expect(api.afterQuery(testResponse1)).toEqual([]);
expect(api.afterQuery(testResponse2)).toEqual(providers);
});

test('getProviders should query with customerId param added', () => {
api = new AvProviders(mockHttp, Promise);
api.query = jest.fn();
Expand Down
13 changes: 0 additions & 13 deletions packages/api-core/src/resources/tests/regions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,6 @@ describe('AvRegions', () => {
expect(api).toBeDefined();
});

test('afterGet should return response.data.regions if it exists or an empty array', () => {
api = new AvRegions(mockHttp, Promise, mockAvUsers);
const testResponse1 = {};
const regions = ['testOrg'];
const testResponse2 = {
data: {
regions,
},
};
expect(api.afterGet(testResponse1)).toEqual([]);
expect(api.afterGet(testResponse2)).toEqual(regions);
});

test('afterUpdate should call setPageBust and return response', () => {
api = new AvRegions(mockHttp, Promise, mockAvUsers);
api.setPageBust = jest.fn();
Expand Down
13 changes: 0 additions & 13 deletions packages/api-core/src/resources/tests/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ describe('AvUsers', () => {
expect(api).toBeDefined();
});

test('afterGet should return response.data.user if it exists or an empty object', () => {
api = new AvUsers(mockHttp, Promise);
const testResponse1 = {};
const user = ['testUser'];
const testResponse2 = {
data: {
user,
},
};
expect(api.afterGet(testResponse1)).toEqual({});
expect(api.afterGet(testResponse2)).toEqual(user);
});

test("me() should get with id 'me'", () => {
api = new AvUsers(mockHttp, Promise);
api.get = jest.fn();
Expand Down
4 changes: 1 addition & 3 deletions packages/api-core/src/resources/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export default class AvUsers extends AvApi {
);
super(http, promise, thisConfig);
}
afterGet(response) {
return (response && response.data && response.data.user) || {};
}

me(config) {
return this.get('me', config);
}
Expand Down

0 comments on commit 6f17d3a

Please sign in to comment.