Add getAllFromDatabase service for each config type

pull/1/head
Boaz Poolman 2021-03-24 18:36:16 +01:00
parent 4f0cce1b54
commit 8a705e91b9
3 changed files with 65 additions and 0 deletions

View File

@ -43,6 +43,22 @@ module.exports = {
}
},
/**
* Get all core-store config from the db.
*
* @returns {object} Object with key value pairs of configs.
*/
getAllFromDatabase: async () => {
const coreStore = await strapi.query(coreStoreQueryString).find({ _limit: -1 });
let configs = {};
Object.values(coreStore).map( ({ id, value, ...config }) => {
configs[`${configPrefix}.${config.key}`] = { value: JSON.parse(value), ...config };
});
return configs;
},
/**
* Import all core-store config files into the db.
*

View File

@ -63,6 +63,39 @@ module.exports = {
}
},
/**
* Get all role-permissions config from the db.
*
* @returns {object} Object with key value pairs of configs.
*/
getAllFromDatabase: async () => {
const service =
strapi.plugins['users-permissions'].services.userspermissions;
const [roles, plugins] = await Promise.all([
service.getRoles(),
service.getPlugins(),
]);
const rolesWithPermissions = await Promise.all(
roles.map(async role => service.getRole(role.id, plugins))
);
const sanitizedRolesArray = rolesWithPermissions.map(role =>
sanitizeEntity(role, {
model: strapi.plugins['users-permissions'].models.role,
})
);
let configs = {};
Object.values(sanitizedRolesArray).map((config) => {
configs[`${configPrefix}.${config.type}`] = config;
});
return configs;
},
/**
* Import all role-permissions config files into the db.
*

View File

@ -40,6 +40,22 @@ module.exports = {
}
},
/**
* Get all webhook config from the db.
*
* @returns {object} Object with key value pairs of configs.
*/
getAllFromDatabase: async () => {
const webhooks = await strapi.query(webhookQueryString).find({ _limit: -1 });
let configs = {};
Object.values(webhooks).map( (config) => {
configs[`${configPrefix}.${config.id}`] = config;
});
return configs;
},
/**
* Import all webhook config files into the db.
*