mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
8984c0ae32
refs https://github.com/TryGhost/Ghost/issues/10318 - primary change is in the settings service which is the only place we fetch the settings endpoint - mocked APIs and fixture data updated to expect and to filter on `?group` rather than `?type`
41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
export default function mockSettings(server) {
|
|
server.get('/settings/', function ({db}, {queryParams}) {
|
|
let {group} = queryParams;
|
|
let filters = group.split(',');
|
|
let settings = [];
|
|
|
|
if (!db.settings.length) {
|
|
server.loadFixtures('settings');
|
|
}
|
|
|
|
filters.forEach((groupFilter) => {
|
|
settings.pushObjects(db.settings.where({group: groupFilter}));
|
|
});
|
|
|
|
return {
|
|
settings,
|
|
meta: {filters: {group}}
|
|
};
|
|
});
|
|
|
|
server.put('/settings/', function ({db}, {requestBody}) {
|
|
let newSettings = JSON.parse(requestBody).settings;
|
|
|
|
newSettings.forEach((newSetting) => {
|
|
let {key} = newSetting;
|
|
|
|
if (db.settings.where({key}).length > 0) {
|
|
db.settings.update({key}, newSetting);
|
|
} else {
|
|
newSetting.group = newSetting.group || 'site';
|
|
db.settings.insert(newSetting);
|
|
}
|
|
});
|
|
|
|
return {
|
|
meta: {},
|
|
settings: db.settings
|
|
};
|
|
});
|
|
}
|