2016-05-24 15:06:59 +03:00
|
|
|
import ApplicationAdapter from 'ghost-admin/adapters/application';
|
2022-10-12 16:03:54 +03:00
|
|
|
import {pluralize} from 'ember-inflector';
|
2014-06-20 06:29:49 +04:00
|
|
|
|
2022-02-02 19:57:22 +03:00
|
|
|
export default class Setting extends ApplicationAdapter {
|
2015-10-28 14:36:45 +03:00
|
|
|
updateRecord(store, type, record) {
|
|
|
|
let data = {};
|
|
|
|
let serializer = store.serializerFor(type.modelName);
|
2014-06-20 06:29:49 +04:00
|
|
|
|
|
|
|
// remove the fake id that we added onto the model.
|
|
|
|
delete record.id;
|
|
|
|
|
|
|
|
// use the SettingSerializer to transform the model back into
|
|
|
|
// an array of settings objects like the API expects
|
|
|
|
serializer.serializeIntoHash(data, type, record);
|
|
|
|
|
2022-10-12 16:03:54 +03:00
|
|
|
// Do not send empty data to the API
|
|
|
|
// This can probably be removed then this is fixed:
|
|
|
|
// https://github.com/TryGhost/Ghost/blob/main/ghost/api-framework/lib/validators/input/all.js#L128
|
|
|
|
let root = pluralize(type.modelName);
|
|
|
|
if (data[root].length === 0) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2014-06-20 06:29:49 +04:00
|
|
|
// use the ApplicationAdapter's buildURL method but do not
|
|
|
|
// pass in an id.
|
2015-10-28 14:36:45 +03:00
|
|
|
return this.ajax(this.buildURL(type.modelName), 'PUT', {data});
|
2014-06-20 06:29:49 +04:00
|
|
|
}
|
2022-02-02 19:57:22 +03:00
|
|
|
}
|