2019-06-21 15:18:26 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import ApplicationAdapter from './application';
|
2020-10-19 16:42:01 +00:00
|
|
|
import { task } from 'ember-concurrency';
|
2019-06-21 15:18:26 +00:00
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
namespace: 'v1',
|
|
|
|
urlForItem() {},
|
2020-10-19 16:42:01 +00:00
|
|
|
dynamicApiPath: '',
|
|
|
|
getDynamicApiPath: task(function*(id) {
|
|
|
|
let result = yield this.store.peekRecord('auth-method', id);
|
|
|
|
this.dynamicApiPath = result.apiPath;
|
|
|
|
return;
|
|
|
|
}),
|
2019-10-17 23:19:14 +00:00
|
|
|
|
2020-10-19 16:42:01 +00:00
|
|
|
fetchByQuery: task(function*(store, query, isList) {
|
2019-10-17 23:19:14 +00:00
|
|
|
const { id } = query;
|
2019-06-21 15:18:26 +00:00
|
|
|
let data = {};
|
2019-10-17 23:19:14 +00:00
|
|
|
if (isList) {
|
|
|
|
data.list = true;
|
2020-10-19 16:42:01 +00:00
|
|
|
yield this.getDynamicApiPath.perform(id);
|
2019-06-21 15:18:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-19 16:42:01 +00:00
|
|
|
return this.ajax(this.urlForItem(id, isList, this.dynamicApiPath), 'GET', { data }).then(resp => {
|
2019-06-21 15:18:26 +00:00
|
|
|
const data = {
|
|
|
|
id,
|
2019-10-17 23:19:14 +00:00
|
|
|
method: id,
|
2019-06-21 15:18:26 +00:00
|
|
|
};
|
|
|
|
return assign({}, resp, data);
|
|
|
|
});
|
2020-10-19 16:42:01 +00:00
|
|
|
}),
|
2019-06-21 15:18:26 +00:00
|
|
|
|
|
|
|
query(store, type, query) {
|
2020-10-19 16:42:01 +00:00
|
|
|
return this.fetchByQuery.perform(store, query, true);
|
2019-06-21 15:18:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
queryRecord(store, type, query) {
|
2020-10-19 16:42:01 +00:00
|
|
|
return this.fetchByQuery.perform(store, query);
|
2019-06-21 15:18:26 +00:00
|
|
|
},
|
|
|
|
});
|