Skip to content

Commit

Permalink
enable adapterOptions to be used in buildURL method
Browse files Browse the repository at this point in the history
  • Loading branch information
Falibur committed Jun 12, 2018
1 parent 13ae64a commit 93f3fad
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion addon/utils/build-url.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { assert } from '@ember/debug';

export function buildOperationUrl(record, opPath, urlType, instance = true) {
export function buildOperationUrl(record, opPath, urlType, adapterOptions, instance = true) {
assert('You must provide a path for instanceOp', opPath);
let modelName = record.constructor.modelName || record.constructor.typeKey;
let adapter = record.store.adapterFor(modelName);
let path = opPath;
let snapshot = record._createSnapshot();
snapshot.adapterOptions = adapterOptions;

let baseUrl = adapter.buildURL(modelName, instance ? record.get('id') : null, snapshot, urlType);

if (baseUrl.charAt(baseUrl.length - 1) === '/') {
Expand Down
4 changes: 2 additions & 2 deletions addon/utils/collection-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { merge } from '@ember/polyfills';
import { buildOperationUrl } from './build-url';

export default function instanceOp(options) {
return function(payload) {
return function(payload, adapterOptions = {}) {
let modelName = this.constructor.modelName || this.constructor.typeKey;
let requestType = (options.type || 'PUT').toUpperCase();
let urlType = options.urlType || requestType;
let adapter = this.store.adapterFor(modelName);
let fullUrl = buildOperationUrl(this, options.path, urlType, false);
let fullUrl = buildOperationUrl(this, options.path, urlType, adapterOptions, false);
return adapter.ajax(fullUrl, requestType, merge(options.ajaxOptions || {}, { data: payload }));
};
}
4 changes: 2 additions & 2 deletions addon/utils/member-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { merge } from '@ember/polyfills';
import { buildOperationUrl } from './build-url';

export default function instanceOp(options) {
return function(payload) {
return function(payload, adapterOptions = {}) {
let modelName = this.constructor.modelName || this.constructor.typeKey;
let requestType = (options.type || 'PUT').toUpperCase();
let urlType = options.urlType || requestType;
let adapter = this.store.adapterFor(modelName);
let fullUrl = buildOperationUrl(this, options.path, urlType);
let fullUrl = buildOperationUrl(this, options.path, urlType, adapterOptions);
return adapter.ajax(fullUrl, requestType, merge(options.ajaxOptions || {}, { data: payload }));
};
}

0 comments on commit 93f3fad

Please sign in to comment.