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 => { module.exports = () => new LifecycleManager();
return new LifecycleManager(strapi);
};

View File

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

View File

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

View File

@ -50,11 +50,12 @@ const updateNonLocalizedFields = async (entry, { model }) => {
/** /**
* Remove entry from localizations & udpate realted localizations * 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} entry entry to remove from localizations
* @param {Object} options * @param {Object} options
* @param {Object} options.model corresponding model * @param {Object} options.model corresponding model
*/ */
const removeEntryFromLocalizations = async (entry, { model }) => { const removeEntryFromRelatedLocalizations = async (entry, { model }) => {
if (Array.isArray(entry.localizations)) { if (Array.isArray(entry.localizations)) {
const newLocalizations = entry.localizations.filter(({ id }) => id != entry.id); const newLocalizations = entry.localizations.filter(({ id }) => id != entry.id);
@ -70,5 +71,5 @@ module.exports = {
assignDefaultLocale, assignDefaultLocale,
addLocalizations, addLocalizations,
updateNonLocalizedFields, updateNonLocalizedFields,
removeEntryFromLocalizations, removeEntryFromRelatedLocalizations,
}; };