Move general settings to specific controllers and services

This commit is contained in:
Alexandre Bodin 2019-07-22 12:15:16 +02:00
parent e6a6c3ee02
commit 47d6e8d73a
3 changed files with 68 additions and 2 deletions

View File

@ -3,7 +3,7 @@
{
"method": "GET",
"path": "/general-settings",
"handler": "ContentTypes.getGeneralSettings",
"handler": "GeneralSettings.getGeneralSettings",
"config": {
"policies": []
}
@ -11,7 +11,7 @@
{
"method": "PUT",
"path": "/general-settings",
"handler": "ContentTypes.updateGeneralSettings",
"handler": "GeneralSettings.updateGeneralSettings",
"config": {
"policies": []
}

View File

@ -0,0 +1,45 @@
'use strict';
const { generalSettingsSchema } = require('./validation');
module.exports = {
/**
* Returns the general content manager settings
*/
async getGeneralSettings(ctx) {
const contentTypeService =
strapi.plugins['content-manager'].services.contenttypes;
const generalSettings = await contentTypeService.getGeneralSettings();
ctx.body = { data: generalSettings };
},
/**
* Update the general content manager settings
* and the content types settings imapcted by it
*/
async updateGeneralSettings(ctx) {
const { body = {} } = ctx.request;
const contentTypeService =
strapi.plugins['content-manager'].services.contenttypes;
let data;
try {
data = await generalSettingsSchema.validate(body, {
abortEarly: false,
stripUnknown: true,
strict: true,
});
} catch (error) {
return ctx.badRequest(null, {
name: 'validationError',
errors: error.errors,
});
}
await contentTypeService.setGeneralSettings(data);
ctx.body = { data };
},
};

View File

@ -0,0 +1,21 @@
'use strict';
const storeUtils = require('./utils/store');
const defaultGeneralSettings = {
searchable: true,
filterable: true,
bulkable: true,
pageSize: 10,
};
module.exports = {
async getGeneralSettings() {
const generalSettings = await storeUtils.getGeneralSettings();
return generalSettings || defaultGeneralSettings;
},
setGeneralSettings(data) {
return storeUtils.setGeneralSettings(data);
},
};