1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/mirage/config/settings.js
Kevin Ansfield 69c51940af add final theme management acceptance tests
refs https://github.com/TryGhost/Ghost-Admin/pull/210
- adds missing acceptance tests for theme deletion
- adds theme deletion endpoint to mirage config
- fixes mirage settings update endpoint (was previously removing config that the client didn't send and also losing the `type` key for all entries preventing the `GET` request from working properly)
2016-08-23 15:27:46 +01:00

46 lines
1.3 KiB
JavaScript

export default function mockSettings(server) {
server.get('/settings/', function (db, request) {
let filters = request.queryParams.type.split(',');
let settings = [];
filters.forEach((filter) => {
settings.pushObjects(db.settings.where({type: filter}));
});
return {
settings,
meta: {
filters: {
type: request.queryParams.type
}
}
};
});
server.put('/settings/', function (db, request) {
let newSettings = JSON.parse(request.requestBody).settings;
newSettings.forEach((newSetting) => {
db.settings.update({key: newSetting.key}, newSetting);
});
let [activeTheme] = db.settings.where({key: 'activeTheme'});
let [availableThemes] = db.settings.where({key: 'availableThemes'});
availableThemes.value.forEach((theme) => {
if (theme.name === activeTheme.value) {
theme.active = true;
} else {
theme.active = false;
}
});
db.settings.remove({key: 'availableThemes'});
db.settings.insert(availableThemes);
return {
meta: {},
settings: db.settings
};
});
}