refactor(logo-customization): simplified updateProjectSettings service function signature

This commit is contained in:
vincentbpro 2022-04-15 09:58:35 +02:00
parent 5fde7a23d0
commit ba8cb27bb1
2 changed files with 8 additions and 8 deletions

View File

@ -61,7 +61,7 @@ module.exports = {
const formatedFiles = await projectSettingsService.parseFilesData(files); const formatedFiles = await projectSettingsService.parseFilesData(files);
await validateUpdateProjectSettingsImagesDimensions(formatedFiles); await validateUpdateProjectSettingsImagesDimensions(formatedFiles);
return projectSettingsService.updateProjectSettings({ body, files: formatedFiles }); return projectSettingsService.updateProjectSettings({ ...body, ...formatedFiles });
}, },
async information() { async information() {

View File

@ -75,7 +75,11 @@ const getProjectSettings = async () => {
const uploadFiles = async (files = {}) => { const uploadFiles = async (files = {}) => {
// Call the provider upload function for each file // Call the provider upload function for each file
return Promise.all(Object.values(files).map(strapi.plugin('upload').provider.uploadStream)); return Promise.all(
Object.values(files)
.filter(file => file.stream instanceof fs.ReadStream)
.map(strapi.plugin('upload').provider.uploadStream)
);
}; };
const deleteOldFiles = async ({ previousSettings, newSettings }) => { const deleteOldFiles = async ({ previousSettings, newSettings }) => {
@ -106,17 +110,13 @@ const deleteOldFiles = async ({ previousSettings, newSettings }) => {
); );
}; };
const updateProjectSettings = async ({ body, files }) => { const updateProjectSettings = async newSettings => {
const store = strapi.store({ type: 'core', name: 'admin' }); const store = strapi.store({ type: 'core', name: 'admin' });
const previousSettings = await store.get({ key: 'project-settings' }); const previousSettings = await store.get({ key: 'project-settings' });
const files = pick(newSettings, PROJECT_SETTINGS_FILE_INPUTS);
await uploadFiles(files); await uploadFiles(files);
const newSettings = {
...body,
...files,
};
PROJECT_SETTINGS_FILE_INPUTS.forEach(inputName => { PROJECT_SETTINGS_FILE_INPUTS.forEach(inputName => {
// If the user input exists but is not a formdata "file" remove it // If the user input exists but is not a formdata "file" remove it
if (newSettings[inputName] !== undefined && !(typeof newSettings[inputName] === 'object')) { if (newSettings[inputName] !== undefined && !(typeof newSettings[inputName] === 'object')) {