Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable adapterOptions to be used in buildURL method #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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