From 93f3fad4d351ba3faf932cf9bd2f44fe3132ce04 Mon Sep 17 00:00:00 2001 From: Falibur Date: Tue, 12 Jun 2018 15:09:20 +0200 Subject: [PATCH] enable adapterOptions to be used in buildURL method --- addon/utils/build-url.js | 4 +++- addon/utils/collection-action.js | 4 ++-- addon/utils/member-action.js | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/addon/utils/build-url.js b/addon/utils/build-url.js index 02a31e310..87624fea8 100644 --- a/addon/utils/build-url.js +++ b/addon/utils/build-url.js @@ -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) === '/') { diff --git a/addon/utils/collection-action.js b/addon/utils/collection-action.js index 7d6e993d6..3c35bd6b9 100644 --- a/addon/utils/collection-action.js +++ b/addon/utils/collection-action.js @@ -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 })); }; } diff --git a/addon/utils/member-action.js b/addon/utils/member-action.js index 51b3f4a6c..c76d85c82 100644 --- a/addon/utils/member-action.js +++ b/addon/utils/member-action.js @@ -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 })); }; }