Skip to content

Commit f969ea0

Browse files
committed
Closes #133.
1 parent 615699e commit f969ea0

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
###### Backwards compatible API changes
77
- #132 - Added `findHasMany` option and capability to `DS.inject`
8+
- #133 - Override resource end point in async methods
89
- #136 - Add a way to force computed properties to be computed. Added `DS.compute`. Added `DSCompute` to prototype of instances.
910
- #137 - Add `DS.link`, `DS.linkAll`, and `DS.linkInverse`, and added `linkInverse` option to `DS.inject`
1011

src/adapters/http.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ function DSHttpAdapterProvider() {
228228
* @param {string|number} id Primary key of the entity to update.
229229
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
230230
*
231-
* - `{string=}` - `baseUrl` - Base url to use.
231+
* - `{string=}` - `baseUrl` - Override the default base url.
232+
* - `{string=}` - `endpoint` - Override the default endpoint.
232233
* - `{object=}` - `params` - Additional query string parameters to add to the url.
233234
*
234235
* @returns {Promise} Promise.
@@ -259,7 +260,8 @@ function DSHttpAdapterProvider() {
259260
* @param {object=} params Search query parameters. See the [query guide](/documentation/guide/queries/index).
260261
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
261262
*
262-
* - `{string=}` - `baseUrl` - Base url to use.
263+
* - `{string=}` - `baseUrl` - Override the default base url.
264+
* - `{string=}` - `endpoint` - Override the default endpoint.
263265
* - `{object=}` - `params` - Additional query string parameters to add to the url.
264266
*
265267
* @returns {Promise} Promise.
@@ -295,7 +297,8 @@ function DSHttpAdapterProvider() {
295297
* @param {object} attrs The attribute payload.
296298
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
297299
*
298-
* - `{string=}` - `baseUrl` - Base url to use.
300+
* - `{string=}` - `baseUrl` - Override the default base url.
301+
* - `{string=}` - `endpoint` - Override the default endpoint.
299302
* - `{object=}` - `params` - Additional query string parameters to add to the url.
300303
*
301304
* @returns {Promise} Promise.
@@ -328,7 +331,8 @@ function DSHttpAdapterProvider() {
328331
* @param {object} attrs The attribute payload.
329332
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
330333
*
331-
* - `{string=}` - `baseUrl` - Base url to use.
334+
* - `{string=}` - `baseUrl` - Override the default base url.
335+
* - `{string=}` - `endpoint` - Override the default endpoint.
332336
* - `{object=}` - `params` - Additional query string parameters to add to the url.
333337
*
334338
* @returns {Promise} Promise.
@@ -361,7 +365,8 @@ function DSHttpAdapterProvider() {
361365
* @param {object=} params Search query parameters. See the [query guide](/documentation/guide/queries/index).
362366
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
363367
*
364-
* - `{string=}` - `baseUrl` - Base url to use.
368+
* - `{string=}` - `baseUrl` - Override the default base url.
369+
* - `{string=}` - `endpoint` - Override the default endpoint.
365370
* - `{object=}` - `params` - Additional query string parameters to add to the url.
366371
*
367372
* @returns {Promise} Promise.
@@ -398,7 +403,8 @@ function DSHttpAdapterProvider() {
398403
* @param {string|number} id Primary key of the entity to update.
399404
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
400405
*
401-
* - `{string=}` - `baseUrl` - Base url to use.
406+
* - `{string=}` - `baseUrl` - Override the default base url.
407+
* - `{string=}` - `endpoint` - Override the default endpoint.
402408
* - `{object=}` - `params` - Additional query string parameters to add to the url.
403409
*
404410
* @returns {Promise} Promise.
@@ -429,7 +435,8 @@ function DSHttpAdapterProvider() {
429435
* @param {object=} params Search query parameters. See the [query guide](/documentation/guide/queries/index).
430436
* @param {object=} options Optional configuration. Also passed along to `$http([config])`. Properties:
431437
*
432-
* - `{string=}` - `baseUrl` - Base url to use.
438+
* - `{string=}` - `baseUrl` - Override the default base url.
439+
* - `{string=}` - `endpoint` - Override the default endpoint.
433440
* - `{object=}` - `params` - Additional query string parameters to add to the url.
434441
*
435442
* @returns {Promise} Promise.

src/datastore/sync_methods/defineResource.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ function defineResource(definition) {
152152
var parentKey = this.parentKey;
153153
var item;
154154
var endpoint;
155+
var thisEndpoint = options.endpoint || this.endpoint;
156+
delete options.endpoint;
155157
options = options || {};
156158
options.params = options.params || {};
157159
if (parent && parentKey && definitions[parent] && options.params[parentKey] !== false) {
@@ -160,19 +162,19 @@ function defineResource(definition) {
160162
}
161163
if (DS.utils.isObject(attrs) && parentKey in attrs) {
162164
delete options.params[parentKey];
163-
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), attrs[parentKey], this.endpoint);
165+
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), attrs[parentKey], thisEndpoint);
164166
} else if (item && parentKey in item) {
165167
delete options.params[parentKey];
166-
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), item[parentKey], this.endpoint);
168+
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), item[parentKey], thisEndpoint);
167169
} else if (options && options.params[parentKey]) {
168-
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), options.params[parentKey], this.endpoint);
170+
endpoint = DS.utils.makePath(definitions[parent].getEndpoint(attrs, options), options.params[parentKey], thisEndpoint);
169171
delete options.params[parentKey];
170172
}
171173
}
172174
if (options.params[parentKey] === false) {
173175
delete options.params[parentKey];
174176
}
175-
return endpoint || this.endpoint;
177+
return endpoint || thisEndpoint;
176178
};
177179

178180
// Remove this in v0.11.0 and make a breaking change notice

0 commit comments

Comments
 (0)