Fix typos & remove unecessary parameter

This commit is contained in:
Alexandre Bodin 2021-02-17 16:59:46 +01:00
parent c1da5a5685
commit e7189d2578
4 changed files with 10 additions and 11 deletions

View File

@ -30,6 +30,4 @@ class LifecycleManager {
}
}
module.exports = strapi => {
return new LifecycleManager(strapi);
};
module.exports = () => new LifecycleManager();

View File

@ -31,7 +31,7 @@ module.exports = async () => {
strapi.db.lifecycles.register({
model: model.uid,
async beforeCreate(data) {
await getService('lcoalizations').assignDefaultLocale(data);
await getService('localizations').assignDefaultLocale(data);
},
async afterCreate(entry) {
await getService('localizations').addLocalizations(entry, { model });
@ -40,7 +40,7 @@ module.exports = async () => {
await getService('localizations').updateNonLocalizedFields(entry, { model });
},
async afterDelete(entry) {
await getService('localizations').removeEntryFromLocalizations(entry, { model });
await getService('localizations').removeEntryFromRelatedLocalizations(entry, { model });
},
});
});

View File

@ -4,7 +4,7 @@ const {
assignDefaultLocale,
addLocalizations,
updateNonLocalizedFields,
removeEntryFromLocalizations,
removeEntryFromRelatedLocalizations,
} = require('../localizations');
const model = {
@ -164,7 +164,7 @@ describe('localizations service', () => {
});
});
describe('removeEntryFromLocalizations', () => {
describe('removeEntryFromRelatedLocalizations', () => {
test('Does nothing if no localizations set', async () => {
const update = jest.fn();
global.strapi = {
@ -175,7 +175,7 @@ describe('localizations service', () => {
const entry = { id: 1, locale: 'test' };
await removeEntryFromLocalizations(entry, { model });
await removeEntryFromRelatedLocalizations(entry, { model });
expect(update).not.toHaveBeenCalled();
});
@ -197,7 +197,7 @@ describe('localizations service', () => {
],
};
await removeEntryFromLocalizations(entry, { model });
await removeEntryFromRelatedLocalizations(entry, { model });
expect(update).toHaveBeenCalledTimes(1);
expect(update).toHaveBeenCalledWith(

View File

@ -50,11 +50,12 @@ const updateNonLocalizedFields = async (entry, { model }) => {
/**
* Remove entry from localizations & udpate realted localizations
* This method should be used only after an entry is deleted
* @param {Object} entry entry to remove from localizations
* @param {Object} options
* @param {Object} options.model corresponding model
*/
const removeEntryFromLocalizations = async (entry, { model }) => {
const removeEntryFromRelatedLocalizations = async (entry, { model }) => {
if (Array.isArray(entry.localizations)) {
const newLocalizations = entry.localizations.filter(({ id }) => id != entry.id);
@ -70,5 +71,5 @@ module.exports = {
assignDefaultLocale,
addLocalizations,
updateNonLocalizedFields,
removeEntryFromLocalizations,
removeEntryFromRelatedLocalizations,
};