|
1 | 1 | /** |
2 | 2 | * @author Jason Dobry <jason.dobry@gmail.com> |
3 | 3 | * @file js-data-angular.js |
4 | | -* @version 2.0.0-alpha.3-0 - Homepage <http://www.js-data.io/js-data-angular/> |
| 4 | +* @version 2.0.0-alpha.3-1 - Homepage <http://www.js-data.io/js-data-angular/> |
5 | 5 | * @copyright (c) 2014 Jason Dobry <https://github.com/jmdobry/> |
6 | 6 | * @license MIT <https://github.com/js-data/js-data-angular/blob/master/LICENSE> |
7 | 7 | * |
|
295 | 295 |
|
296 | 296 | var dsHttpAdapterPrototype = DSHttpAdapter.prototype; |
297 | 297 |
|
298 | | - dsHttpAdapterPrototype.getIdPath = function (resourceConfig, options, id) { |
299 | | - return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(id, options), id); |
300 | | - }; |
301 | | - |
302 | | - dsHttpAdapterPrototype.getAllPath = function (resourceConfig, options) { |
303 | | - return makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(null, options)); |
| 298 | + dsHttpAdapterPrototype.getPath = function (method, resourceConfig, id, options) { |
| 299 | + var _this = this; |
| 300 | + options = options || {}; |
| 301 | + var args = [ |
| 302 | + options.basePath || _this.defaults.basePath || resourceConfig.basePath, |
| 303 | + resourceConfig.getEndpoint((DSUtils.isString(id) || DSUtils.isNumber(id) || method === 'create') ? id : null, options) |
| 304 | + ]; |
| 305 | + if (method === 'find' || method === 'update' || method === 'destroy') { |
| 306 | + args.push(id); |
| 307 | + } |
| 308 | + return DSUtils.makePath.apply(DSUtils, args); |
304 | 309 | }; |
305 | 310 |
|
306 | 311 | dsHttpAdapterPrototype.GET = function (url, config) { |
|
349 | 354 | var _this = this; |
350 | 355 | options = options || {}; |
351 | 356 | return _this.GET( |
352 | | - _this.getIdPath(resourceConfig, options, id), |
| 357 | + _this.getPath('find', resourceConfig, id, options), |
353 | 358 | options |
354 | 359 | ).then(function (data) { |
355 | 360 | return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data); |
|
365 | 370 | deepMixIn(options.params, params); |
366 | 371 | } |
367 | 372 | return _this.GET( |
368 | | - _this.getAllPath(resourceConfig, options), |
| 373 | + _this.getPath('findAll', resourceConfig, params, options), |
369 | 374 | options |
370 | 375 | ).then(function (data) { |
371 | 376 | return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data); |
|
376 | 381 | var _this = this; |
377 | 382 | options = options || {}; |
378 | 383 | return _this.POST( |
379 | | - makePath(options.basePath || this.defaults.basePath || resourceConfig.basePath, resourceConfig.getEndpoint(attrs, options)), |
| 384 | + _this.getPath('create', resourceConfig, attrs, options), |
380 | 385 | (options.serialize ? options.serialize : _this.defaults.serialize)(resourceConfig, attrs), |
381 | 386 | options |
382 | 387 | ).then(function (data) { |
|
388 | 393 | var _this = this; |
389 | 394 | options = options || {}; |
390 | 395 | return _this.PUT( |
391 | | - _this.getIdPath(resourceConfig, options, id), |
| 396 | + _this.getPath('update', resourceConfig, id, options), |
392 | 397 | (options.serialize ? options.serialize : _this.defaults.serialize)(resourceConfig, attrs), |
393 | 398 | options |
394 | 399 | ).then(function (data) { |
|
405 | 410 | deepMixIn(options.params, params); |
406 | 411 | } |
407 | 412 | return this.PUT( |
408 | | - _this.getAllPath(resourceConfig, options), |
| 413 | + _this.getPath('updateAll', resourceConfig, attrs, options), |
409 | 414 | (options.serialize ? options.serialize : _this.defaults.serialize)(resourceConfig, attrs), |
410 | 415 | options |
411 | 416 | ).then(function (data) { |
|
417 | 422 | var _this = this; |
418 | 423 | options = options || {}; |
419 | 424 | return _this.DEL( |
420 | | - _this.getIdPath(resourceConfig, options, id), |
| 425 | + _this.getPath('destroy', resourceConfig, id, options), |
421 | 426 | options |
422 | 427 | ).then(function (data) { |
423 | 428 | return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data); |
|
433 | 438 | deepMixIn(options.params, params); |
434 | 439 | } |
435 | 440 | return this.DEL( |
436 | | - _this.getAllPath(resourceConfig, options), |
| 441 | + _this.getPath('destroyAll', resourceConfig, params, options), |
437 | 442 | options |
438 | 443 | ).then(function (data) { |
439 | 444 | return (options.deserialize ? options.deserialize : _this.defaults.deserialize)(resourceConfig, data); |
|
0 commit comments