mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
refactor(logo-customization): refactored service function params
This commit is contained in:
parent
02b14f2bb4
commit
bbed67982c
@ -61,7 +61,7 @@ module.exports = {
|
||||
const formatedFiles = await projectSettingsService.parseFilesData(files);
|
||||
await validateUpdateProjectSettingsImagesDimensions(formatedFiles);
|
||||
|
||||
return projectSettingsService.updateProjectSettings(body, formatedFiles);
|
||||
return projectSettingsService.updateProjectSettings({ body, files: formatedFiles });
|
||||
},
|
||||
|
||||
async information() {
|
||||
|
||||
@ -133,7 +133,7 @@ describe('Project setting', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await deleteOldFiles(previousSettings, newSettings);
|
||||
await deleteOldFiles({ previousSettings, newSettings });
|
||||
|
||||
expect(unlinkSync).not.toBeCalled();
|
||||
});
|
||||
@ -150,7 +150,7 @@ describe('Project setting', () => {
|
||||
|
||||
const newSettings = previousSettings;
|
||||
|
||||
await deleteOldFiles(previousSettings, newSettings);
|
||||
await deleteOldFiles({ previousSettings, newSettings });
|
||||
|
||||
expect(unlinkSync).not.toBeCalled();
|
||||
});
|
||||
@ -167,7 +167,7 @@ describe('Project setting', () => {
|
||||
|
||||
const newSettings = { menuLogo: null };
|
||||
|
||||
await deleteOldFiles(previousSettings, newSettings);
|
||||
await deleteOldFiles({ previousSettings, newSettings });
|
||||
|
||||
expect(unlinkSync).toBeCalledTimes(1);
|
||||
expect(unlinkSync).toBeCalledWith(previousSettings.menuLogo.path);
|
||||
@ -190,7 +190,7 @@ describe('Project setting', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await deleteOldFiles(previousSettings, newSettings);
|
||||
await deleteOldFiles({ previousSettings, newSettings });
|
||||
|
||||
expect(unlinkSync).toBeCalledTimes(1);
|
||||
expect(unlinkSync).toBeCalledWith(previousSettings.menuLogo.path);
|
||||
@ -228,7 +228,7 @@ describe('Project setting', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await updateProjectSettings(body, files);
|
||||
await updateProjectSettings({ body, files });
|
||||
|
||||
expect(storeSet).toBeCalledTimes(1);
|
||||
expect(storeSet).toBeCalledWith({
|
||||
@ -245,7 +245,7 @@ describe('Project setting', () => {
|
||||
menuLogo: null,
|
||||
};
|
||||
|
||||
await updateProjectSettings(body, files);
|
||||
await updateProjectSettings({ body, files });
|
||||
|
||||
expect(storeSet).toBeCalledTimes(1);
|
||||
expect(storeSet).toBeCalledWith({
|
||||
@ -268,7 +268,7 @@ describe('Project setting', () => {
|
||||
},
|
||||
};
|
||||
|
||||
await updateProjectSettings(body, files);
|
||||
await updateProjectSettings({ body, files });
|
||||
|
||||
expect(storeSet).toBeCalledTimes(1);
|
||||
expect(storeSet).toBeCalledWith({
|
||||
|
||||
@ -73,7 +73,7 @@ const uploadFiles = async files => {
|
||||
return Promise.all(Object.values(files).map(strapi.plugin('upload').provider.uploadStream));
|
||||
};
|
||||
|
||||
const deleteOldFiles = async (previousSettings, newSettings) => {
|
||||
const deleteOldFiles = async ({ previousSettings, newSettings }) => {
|
||||
return Promise.all(
|
||||
PROJECT_SETTINGS_FILE_INPUTS.map(async inputName => {
|
||||
// Skip if there was no previous file
|
||||
@ -96,7 +96,7 @@ const deleteOldFiles = async (previousSettings, newSettings) => {
|
||||
);
|
||||
};
|
||||
|
||||
const updateProjectSettings = async (body, files) => {
|
||||
const updateProjectSettings = async ({ body, files }) => {
|
||||
const store = await strapi.store({ type: 'core', name: 'admin' });
|
||||
const previousSettings = await store.get({ key: 'project-settings' });
|
||||
|
||||
@ -126,9 +126,12 @@ const updateProjectSettings = async (body, files) => {
|
||||
|
||||
// No await to proceed asynchronously
|
||||
uploadFiles(files);
|
||||
deleteOldFiles(previousSettings, newSettings);
|
||||
deleteOldFiles({ previousSettings, newSettings });
|
||||
|
||||
store.set({ key: 'project-settings', value: { ...previousSettings, ...newSettings } });
|
||||
await store.set({
|
||||
key: 'project-settings',
|
||||
value: { ...previousSettings, ...newSettings },
|
||||
});
|
||||
|
||||
return getProjectSettings();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user