mirror of
https://github.com/flarum/framework.git
synced 2024-12-13 15:13:42 +08:00
25 lines
807 B
JavaScript
25 lines
807 B
JavaScript
|
import DS from 'ember-data';
|
||
|
|
||
|
// This can be removed when
|
||
|
// https://github.com/emberjs/data/pull/2584 is implemented.
|
||
|
|
||
|
export default {
|
||
|
name: 'find-query-one',
|
||
|
initialize: function(container) {
|
||
|
DS.Store.reopen({
|
||
|
findQueryOne: function(type, id, query) {
|
||
|
var store = this;
|
||
|
var typeClass = store.modelFor(type);
|
||
|
var adapter = store.adapterFor(typeClass);
|
||
|
var serializer = store.serializerFor(typeClass);
|
||
|
var url = adapter.buildURL(type, id);
|
||
|
var ajaxPromise = adapter.ajax(url, 'GET', { data: query });
|
||
|
|
||
|
return ajaxPromise.then(function(rawPayload) {
|
||
|
var extractedPayload = serializer.extract(store, typeClass, rawPayload, id, 'find');
|
||
|
return store.push(typeClass, extractedPayload);
|
||
|
});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
};
|