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 Apr 9, 2019
1 parent 3823ee7 commit 9ed5abb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions addon/utils/build-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export function buildOperationUrl<M extends Model>(
record: M,
opPath: string,
urlType: EmberDataRequestType,
adapterOptions: Object
instance = true
) {
const modelClass = _getModelClass(record);
Expand All @@ -56,6 +57,7 @@ export function buildOperationUrl<M extends Model>(
const adapter = store.adapterFor(modelName);
const path = opPath;
const snapshot = snapshotFromRecord(record);
snapshot.adapterOptions = adapterOptions;
const baseUrl = adapter.buildURL(modelName, instance ? record.get('id') : null, snapshot, urlType);

if (!path) {
Expand Down
4 changes: 2 additions & 2 deletions addon/utils/collection-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ export interface CollectionOperationOptions<IN, OUT> {
}

export default function collectionOp<IN = any, OUT = any>(options: CollectionOperationOptions<IN, OUT>) {
return function runCollectionOp(this: Model, payload: IN): Promise<OUT> {
return function runCollectionOp(this: Model, payload: IN, adapterOptions = {}): Promise<OUT> {
const model: Model = this;
const recordClass = _getModelClass(model);
const modelName = _getModelName(recordClass);
const store = _getStoreFromRecord(model);
const requestType: HTTPVerb = strictifyHttpVerb(options.type || 'put');
const urlType: EmberDataRequestType = options.urlType || 'updateRecord';
const adapter = store.adapterFor(modelName);
const fullUrl = buildOperationUrl(model, options.path, urlType, false);
const fullUrl = buildOperationUrl(model, options.path, urlType, adapterOptions, false);
const data = (options.before && options.before.call(model, payload)) || payload;
return adapter
.ajax(fullUrl, requestType, assign(options.ajaxOptions || {}, { data }))
Expand Down
4 changes: 2 additions & 2 deletions addon/utils/member-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export interface InstanceOperationOptions<IN, OUT> {
}

export default function instanceOp<IN = any, OUT = any>(options: InstanceOperationOptions<IN, OUT>) {
return function runInstanceOp(this: Model, payload: IN): Promise<OUT> {
return function runInstanceOp(this: Model, payload: IN, adapterOptions = {}): Promise<OUT> {
const recordClass = _getModelClass(this);
const modelName = _getModelName(recordClass);
const store = _getStoreFromRecord(this);
const { ajaxOptions, path, before, after, type = 'put', urlType = 'updateRecord' } = options;
const requestType: HTTPVerb = strictifyHttpVerb(type);
const adapter = store.adapterFor(modelName);
const fullUrl = buildOperationUrl(this, path, urlType);
const fullUrl = buildOperationUrl(this, path, urlType, adapterOptions);
const data = (before && before.call(this, payload)) || payload;
return adapter.ajax(fullUrl, requestType, assign(ajaxOptions || {}, { data })).then((response: JSONValue) => {
if (after && !this.isDestroyed) {
Expand Down

0 comments on commit 9ed5abb

Please sign in to comment.