mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
Move general settings to specific controllers and services
This commit is contained in:
parent
e6a6c3ee02
commit
47d6e8d73a
@ -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": []
|
||||
}
|
||||
|
||||
@ -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 };
|
||||
},
|
||||
};
|
||||
@ -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);
|
||||
},
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user