mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 10:55:37 +00:00
Fix typos & remove unecessary parameter
This commit is contained in:
parent
c1da5a5685
commit
e7189d2578
@ -30,6 +30,4 @@ class LifecycleManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = strapi => {
|
module.exports = () => new LifecycleManager();
|
||||||
return new LifecycleManager(strapi);
|
|
||||||
};
|
|
||||||
|
|||||||
@ -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 });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -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(
|
||||||
|
|||||||
@ -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,
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user