Skip to content

Commit 54b0a49

Browse files
committed
Update new format API Client to support v0.9 of admin-on-rest
1 parent fd04bd0 commit 54b0a49

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

lib/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,18 @@ exports.default = function (apiUrl) {
138138

139139
switch (type) {
140140
case _types.GET_LIST:
141+
case _types.GET_MANY_REFERENCE:
141142
if (!headers.has('x-total-count')) {
142143
throw new Error('The X-Total-Count header is missing in the HTTP Response. The jsonServer REST client expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?');
143144
}
144145
return {
145-
data: json.map(function (x) {
146-
return x;
147-
}),
146+
data: json,
148147
total: parseInt(headers.get('x-total-count').split('/').pop(), 10)
149148
};
150149
case _types.CREATE:
151-
return _extends({}, params.data, { id: json.id });
150+
return { data: _extends({}, params.data, { id: json.id }) };
152151
default:
153-
return json;
152+
return { data: json };
154153
}
155154
};
156155

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "aor-loopback",
3-
"version": "1.0.8",
3+
"version": "1.1.0",
44
"description": "Loopback-style REST Client for Admin-on-rest, the frontend framework for building admin applications on top of REST services",
55
"main": "lib/index.js",
66
"scripts": {

src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,18 @@ export default (apiUrl, httpClient = fetchJson) => {
109109
const {headers, json} = response;
110110
switch (type) {
111111
case GET_LIST:
112+
case GET_MANY_REFERENCE:
112113
if (!headers.has('x-total-count')) {
113114
throw new Error('The X-Total-Count header is missing in the HTTP Response. The jsonServer REST client expects responses for lists of resources to contain this header with the total number of results to build the pagination. If you are using CORS, did you declare X-Total-Count in the Access-Control-Expose-Headers header?');
114115
}
115116
return {
116-
data: json.map(x => x),
117+
data: json,
117118
total: parseInt(headers.get('x-total-count').split('/').pop(), 10),
118119
};
119120
case CREATE:
120-
return {...params.data, id: json.id};
121+
return { data: { ...params.data, id: json.id } };
121122
default:
122-
return json;
123+
return { data: json };
123124
}
124125
};
125126

0 commit comments

Comments
 (0)