From 19cc297f748468724d7943aae9eb57e4e4731894 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:02:36 +0200 Subject: [PATCH 01/13] Update rules --- .eslintrc.back.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/.eslintrc.back.js b/.eslintrc.back.js index 1efb19cb0e..802c3f651c 100644 --- a/.eslintrc.back.js +++ b/.eslintrc.back.js @@ -26,14 +26,10 @@ module.exports = { }, ], 'prefer-destructuring': ['error', { AssignmentExpression: { array: false } }], - eqeqeq: 'warn', - 'no-underscore-dangle': 'warn', - 'no-use-before-define': 'warn', - 'no-param-reassign': 'warn', + 'no-underscore-dangle': 'off', + 'no-use-before-define': 'off', 'no-continue': 'warn', 'no-process-exit': 'off', - 'no-plusplus': 'warn', - 'no-loop-func': 'warn', - 'guard-for-in': 'warn', + 'no-loop-func': 'off', }, }; From 3909b91efaabc1e5b105669a2ce35e8a3f990257 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:04:28 +0200 Subject: [PATCH 02/13] Fix eslint in scripts --- .../find-duplicated-translation.js | 4 ++-- scripts/front/merge-duplicated-translations/index.js | 4 ++-- scripts/open-api/serve.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/front/merge-duplicated-translations/find-duplicated-translation.js b/scripts/front/merge-duplicated-translations/find-duplicated-translation.js index fbdf2c79b9..5a366dcc39 100644 --- a/scripts/front/merge-duplicated-translations/find-duplicated-translation.js +++ b/scripts/front/merge-duplicated-translations/find-duplicated-translation.js @@ -13,10 +13,10 @@ const printResults = (results) => { Object.entries(pkgs).forEach(([packageName, keys]) => { keys.forEach((key) => { console.log(`"${chalk.yellow(value)}" ${packageName} ${chalk.blue(key)}`); - keysCount++; + keysCount += 1; }); }); - valuesCount++; + valuesCount += 1; console.log(); }); diff --git a/scripts/front/merge-duplicated-translations/index.js b/scripts/front/merge-duplicated-translations/index.js index 4adec42b2b..b2843bc674 100644 --- a/scripts/front/merge-duplicated-translations/index.js +++ b/scripts/front/merge-duplicated-translations/index.js @@ -137,10 +137,10 @@ const merge = async (valuesToMerge) => { valueGroup.forEach((keyGroup) => { updateTranslationFiles(keyGroup, targetKey); keyGroup.replaceAll(`id: '${targetKey}'`); - mergedCount++; + mergedCount += 1; }); } - current++; + current += 1; } console.log(`Merged ${mergedCount} keys`); diff --git a/scripts/open-api/serve.js b/scripts/open-api/serve.js index 05bb055b58..37657184e5 100644 --- a/scripts/open-api/serve.js +++ b/scripts/open-api/serve.js @@ -25,7 +25,7 @@ async function run() { } const server = http.createServer((req, res) => { - if (req.url == '/spec.yml') { + if (req.url === '/spec.yml') { return fse.createReadStream(openAPISpecPath).pipe(res); } From bba4c4c85a2e9da47666979f318c5cb6c7768ed5 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:05:26 +0200 Subject: [PATCH 03/13] Fix eslint in test utils --- test/unit.setup.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/unit.setup.js b/test/unit.setup.js index f8be50afb8..3ffa10c6f3 100644 --- a/test/unit.setup.js +++ b/test/unit.setup.js @@ -12,11 +12,11 @@ Object.defineProperty(global, 'strapi', { strapiInstance = value; strapiInstance.plugin = (name) => strapiInstance.plugins[name]; - _.mapValues(strapi.plugins, (plugin) => { - plugin.controller = (name) => plugin.controllers[name]; - plugin.service = (name) => plugin.services[name]; - plugin.contentType = (name) => plugin.contentTypes[name]; - plugin.policy = (name) => plugin.policies[name]; + _.mapValues(strapi.plugins, (acc) => { + acc.controller = (name) => acc.controllers[name]; + acc.service = (name) => acc.services[name]; + acc.contentType = (name) => acc.contentTypes[name]; + acc.policy = (name) => acc.policies[name]; }); strapiInstance.service = (name = '') => { From c563955d46914af0f5ac6e644c0f336254068aff Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:07:36 +0200 Subject: [PATCH 04/13] Lighten no-param-reassign --- .eslintrc.back.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.eslintrc.back.js b/.eslintrc.back.js index 802c3f651c..1c079b8326 100644 --- a/.eslintrc.back.js +++ b/.eslintrc.back.js @@ -31,5 +31,11 @@ module.exports = { 'no-continue': 'warn', 'no-process-exit': 'off', 'no-loop-func': 'off', + 'no-param-reassign': [ + 'error', + { + props: false, + }, + ], }, }; From e57f02d2d9491a4e2a9ffe5dcc418b2f909f599f Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:18:24 +0200 Subject: [PATCH 05/13] Fix eslint in plugins folder --- .../plugins/documentation/server/services/documentation.js | 5 +++-- .../server/controllers/content-manager-user.js | 4 ++-- .../plugins/users-permissions/server/controllers/user.js | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/plugins/documentation/server/services/documentation.js b/packages/plugins/documentation/server/services/documentation.js index bbc3383a7a..564b8f595f 100755 --- a/packages/plugins/documentation/server/services/documentation.js +++ b/packages/plugins/documentation/server/services/documentation.js @@ -15,12 +15,13 @@ module.exports = ({ strapi }) => { return { registerDoc(doc) { + let registeredDoc = doc; // parseYaml if (typeof doc === 'string') { - doc = require('yaml').parse(doc); + registeredDoc = require('yaml').parse(registeredDoc); } // receive an object we can register it directly - registeredDocs.push(doc); + registeredDocs.push(registeredDoc); }, getDocumentationVersion() { return _.get(config, 'info.version'); diff --git a/packages/plugins/users-permissions/server/controllers/content-manager-user.js b/packages/plugins/users-permissions/server/controllers/content-manager-user.js index be3cfd6aa3..b6e10cd428 100644 --- a/packages/plugins/users-permissions/server/controllers/content-manager-user.js +++ b/packages/plugins/users-permissions/server/controllers/content-manager-user.js @@ -147,7 +147,7 @@ module.exports = { .query('plugin::users-permissions.user') .findOne({ where: { username } }); - if (userWithSameUsername && userWithSameUsername.id != id) { + if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(id)) { throw new ApplicationError('Username already taken'); } } @@ -157,7 +157,7 @@ module.exports = { .query('plugin::users-permissions.user') .findOne({ where: { email: _.toLower(email) } }); - if (userWithSameEmail && userWithSameEmail.id != id) { + if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(id)) { throw new ApplicationError('Email already taken'); } body.email = _.toLower(body.email); diff --git a/packages/plugins/users-permissions/server/controllers/user.js b/packages/plugins/users-permissions/server/controllers/user.js index 88e5b293d9..f096bd83ff 100644 --- a/packages/plugins/users-permissions/server/controllers/user.js +++ b/packages/plugins/users-permissions/server/controllers/user.js @@ -105,7 +105,7 @@ module.exports = { .query('plugin::users-permissions.user') .findOne({ where: { username } }); - if (userWithSameUsername && userWithSameUsername.id != id) { + if (userWithSameUsername && _.toString(userWithSameUsername.id) !== _.toString(id)) { throw new ApplicationError('Username already taken'); } } @@ -115,7 +115,7 @@ module.exports = { .query('plugin::users-permissions.user') .findOne({ where: { email: email.toLowerCase() } }); - if (userWithSameEmail && userWithSameEmail.id != id) { + if (userWithSameEmail && _.toString(userWithSameEmail.id) !== _.toString(id)) { throw new ApplicationError('Email already taken'); } ctx.request.body.email = ctx.request.body.email.toLowerCase(); From 04f218346db2962d5766f4155410eb52ef753c93 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 15:19:02 +0200 Subject: [PATCH 06/13] Fix esint in generators folder --- packages/generators/app/lib/create-customized-project.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/generators/app/lib/create-customized-project.js b/packages/generators/app/lib/create-customized-project.js index b48aad4106..082466d2bd 100644 --- a/packages/generators/app/lib/create-customized-project.js +++ b/packages/generators/app/lib/create-customized-project.js @@ -61,7 +61,7 @@ async function askDbInfosAndTest(scope) { .then((result) => { if (result && result.shouldRetry === true && retries < MAX_RETRIES - 1) { console.log('Retrying...'); - retries++; + retries += 1; return loop(); } }) @@ -86,7 +86,7 @@ async function askDbInfosAndTest(scope) { } console.log('Retrying...'); - retries++; + retries += 1; return loop(); } From 4e989321e3241bda88787b83139de2660586413b Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 16:15:21 +0200 Subject: [PATCH 07/13] Fix eslint core/admin --- packages/core/admin/scripts/build.js | 6 ++---- packages/core/admin/server/services/__tests__/role.test.js | 6 +++++- .../permission/permissions-manager/query-builers.js | 5 +++-- packages/core/admin/server/services/permission/queries.js | 2 +- .../server/tests/admin-permissions-conditions.test.e2e.js | 2 +- packages/core/admin/server/tests/admin-user.test.e2e.js | 2 +- .../common-functions/check-fields-are-correctly-nested.js | 2 +- 7 files changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/core/admin/scripts/build.js b/packages/core/admin/scripts/build.js index 3578b0c38e..4b2a00c5b3 100644 --- a/packages/core/admin/scripts/build.js +++ b/packages/core/admin/scripts/build.js @@ -80,12 +80,10 @@ const buildAdmin = async () => { new Error( messages.errors.reduce((acc, error) => { if (isObject(error)) { - acc += error.message; - } else { - acc += error.join('\n\n'); + return acc + error.message; } - return acc; + return acc + error.join('\n\n'); }, '') ) ); diff --git a/packages/core/admin/server/services/__tests__/role.test.js b/packages/core/admin/server/services/__tests__/role.test.js index 5e537d0d80..d6d0b055b0 100644 --- a/packages/core/admin/server/services/__tests__/role.test.js +++ b/packages/core/admin/server/services/__tests__/role.test.js @@ -426,7 +426,11 @@ describe('Role', () => { const count = jest.fn(() => Promise.resolve(0)); let id = 1; - const create = jest.fn(({ data }) => ({ ...data, id: id++ })); + const create = jest.fn(({ data }) => { + const res = { ...data, id }; + id += 1; + return res; + }); const values = jest.fn(() => actions); const createMany = jest.fn(); const assignARoleToAll = jest.fn(); diff --git a/packages/core/admin/server/services/permission/permissions-manager/query-builers.js b/packages/core/admin/server/services/permission/permissions-manager/query-builers.js index 3f984ee45d..aa6ac6ffc6 100644 --- a/packages/core/admin/server/services/permission/permissions-manager/query-builers.js +++ b/packages/core/admin/server/services/permission/permissions-manager/query-builers.js @@ -49,9 +49,10 @@ const unwrapDeep = (obj) => { if (_.isPlainObject(v)) { if ('$elemMatch' in v) { - v = v.$elemMatch; // removing this key + _.setWith(acc, key, unwrapDeep(v.$elemMatch)); + } else { + _.setWith(acc, key, unwrapDeep(v)); } - _.setWith(acc, key, unwrapDeep(v)); } else if (_.isArray(v)) { // prettier-ignore _.setWith(acc, key, v.map(v => unwrapDeep(v))); diff --git a/packages/core/admin/server/services/permission/queries.js b/packages/core/admin/server/services/permission/queries.js index dc3939ddd5..2dfd476340 100644 --- a/packages/core/admin/server/services/permission/queries.js +++ b/packages/core/admin/server/services/permission/queries.js @@ -144,7 +144,7 @@ const cleanPermissionsInDatabase = async () => { const total = await strapi.query('admin::permission').count(); const pageCount = Math.ceil(total / pageSize); - for (let page = 0; page < pageCount; page++) { + for (let page = 0; page < pageCount; page += 1) { // 1. Find invalid permissions and collect their ID to delete them later const results = await strapi .query('admin::permission') diff --git a/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js b/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js index 909f72174d..3e08b4c92d 100644 --- a/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js +++ b/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js @@ -84,7 +84,7 @@ if (edition === 'EE') { // Create users with the new role & create associated auth requests const users = []; - for (let i = 0; i < localTestData.users.length; ++i) { + for (let i = 1; i < localTestData.users.length; i += 1) { const userFixture = localTestData.users[i]; const userAttributes = { ...userFixture, diff --git a/packages/core/admin/server/tests/admin-user.test.e2e.js b/packages/core/admin/server/tests/admin-user.test.e2e.js index f435c2c809..ba8c6d9c34 100644 --- a/packages/core/admin/server/tests/admin-user.test.e2e.js +++ b/packages/core/admin/server/tests/admin-user.test.e2e.js @@ -145,7 +145,7 @@ describe('Admin User CRUD (e2e)', () => { }; }; - for (let i = 0; i < 3; i++) { + for (let i = 0; i < 3; i += 1) { const res = await rq({ url: '/admin/users', method: 'POST', diff --git a/packages/core/admin/server/validation/common-functions/check-fields-are-correctly-nested.js b/packages/core/admin/server/validation/common-functions/check-fields-are-correctly-nested.js index cd95f534c8..6bc89f367e 100644 --- a/packages/core/admin/server/validation/common-functions/check-fields-are-correctly-nested.js +++ b/packages/core/admin/server/validation/common-functions/check-fields-are-correctly-nested.js @@ -12,7 +12,7 @@ const checkFieldsAreCorrectlyNested = (fields) => { } let failed = false; - for (let indexA = 0; indexA < fields.length; indexA++) { + for (let indexA = 0; indexA < fields.length; indexA += 1) { failed = fields .slice(indexA + 1) .some( From e3d92185f191d7085590e384a4e591ab8c2e8890 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 16:20:10 +0200 Subject: [PATCH 08/13] Fix eslint content-type-builder --- .../server/services/schema-builder/schema-handler.js | 2 +- .../core/content-type-builder/tests/single-type.test.e2e.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core/content-type-builder/server/services/schema-builder/schema-handler.js b/packages/core/content-type-builder/server/services/schema-builder/schema-handler.js index 22b23aff54..da057ed7ad 100644 --- a/packages/core/content-type-builder/server/services/schema-builder/schema-handler.js +++ b/packages/core/content-type-builder/server/services/schema-builder/schema-handler.js @@ -130,7 +130,7 @@ module.exports = function createSchemaHandler(infos) { } // set new Attributes - for (const key in newAttributes) { + for (const key of Object.keys(newAttributes)) { this.setAttribute(key, newAttributes[key]); } diff --git a/packages/core/content-type-builder/tests/single-type.test.e2e.js b/packages/core/content-type-builder/tests/single-type.test.e2e.js index b6c9263bb8..dbc8c2e2ba 100644 --- a/packages/core/content-type-builder/tests/single-type.test.e2e.js +++ b/packages/core/content-type-builder/tests/single-type.test.e2e.js @@ -157,7 +157,7 @@ describe('Content Type Builder - Content types', () => { const { uid } = createRes.body.data; // create data - for (let i = 0; i < 2; i++) { + for (let i = 0; i < 2; i += 1) { await strapi.query(uid).create({ data: { title: 'Test' } }); } From eab835e301df7438438cc048339047a1b8851129 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 16:20:47 +0200 Subject: [PATCH 09/13] Fix eslint content-manager --- packages/core/content-manager/server/services/components.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/content-manager/server/services/components.js b/packages/core/content-manager/server/services/components.js index 2fde38ac95..0ab2b8bbed 100644 --- a/packages/core/content-manager/server/services/components.js +++ b/packages/core/content-manager/server/services/components.js @@ -69,7 +69,7 @@ module.exports = ({ strapi }) => ({ }); }; - for (const key in model.attributes) { + for (const key of Object.keys(model.attributes)) { const attribute = model.attributes[key]; if (attribute.type === 'component') { From 7b9866a77080b3ecd7d25fbee9277fb07c5f4d7f Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 16:23:18 +0200 Subject: [PATCH 10/13] Fix eslint utils --- packages/core/utils/lib/build-query.js | 2 +- packages/core/utils/lib/print-value.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/utils/lib/build-query.js b/packages/core/utils/lib/build-query.js index 8cff188f76..d16612af85 100644 --- a/packages/core/utils/lib/build-query.js +++ b/packages/core/utils/lib/build-query.js @@ -21,7 +21,7 @@ const getAssociationFromFieldKey = ({ model, field }) => { let association; let attribute; - for (let i = 0; i < fieldParts.length; i++) { + for (let i = 0; i < fieldParts.length; i += 1) { const part = fieldParts[i]; attribute = part; diff --git a/packages/core/utils/lib/print-value.js b/packages/core/utils/lib/print-value.js index 7a61bebc7c..4316205893 100644 --- a/packages/core/utils/lib/print-value.js +++ b/packages/core/utils/lib/print-value.js @@ -11,6 +11,7 @@ const symbolToString = typeof Symbol !== 'undefined' ? Symbol.prototype.toString const SYMBOL_REGEXP = /^Symbol\((.*)\)(.*)$/; function printNumber(val) { + // eslint-disable-next-line eqeqeq if (val != +val) return 'NaN'; const isNegativeZero = val === 0 && 1 / val < 0; return isNegativeZero ? '-0' : `${val}`; From 22589cf0e11e69af3f13caf94afa57a940a97cf4 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 17:53:28 +0200 Subject: [PATCH 11/13] Fix eslint core strapi --- .../strapi/lib/commands/configurationDump.js | 4 +- .../lib/core-api/controller/transform.js | 2 +- packages/core/strapi/lib/core/loaders/apis.js | 2 +- .../loaders/plugins/get-enabled-plugins.js | 4 +- .../strapi/lib/core/loaders/plugins/index.js | 10 ++--- .../lib/core/registries/content-types.js | 4 +- .../strapi/lib/core/registries/controllers.js | 4 +- .../core/strapi/lib/core/registries/hooks.js | 2 +- .../strapi/lib/core/registries/middlewares.js | 2 +- .../strapi/lib/core/registries/policies.js | 2 +- .../strapi/lib/core/registries/services.js | 4 +- packages/core/strapi/lib/services/cron.js | 2 +- .../lib/services/entity-service/components.js | 6 +-- .../lib/services/entity-validator/index.js | 39 +++++++++++-------- .../metrics/__tests__/middleware.test.js | 2 +- .../strapi/lib/services/metrics/middleware.js | 2 +- .../lib/services/server/register-routes.js | 4 +- .../strapi/lib/services/utils/upload-files.js | 2 +- .../core/strapi/lib/services/worker-queue.js | 4 +- packages/core/strapi/lib/utils/addSlash.js | 11 +++--- 20 files changed, 60 insertions(+), 52 deletions(-) diff --git a/packages/core/strapi/lib/commands/configurationDump.js b/packages/core/strapi/lib/commands/configurationDump.js index ce0183a84e..4745b94282 100644 --- a/packages/core/strapi/lib/commands/configurationDump.js +++ b/packages/core/strapi/lib/commands/configurationDump.js @@ -9,7 +9,7 @@ const CHUNK_SIZE = 100; * Will dump configurations to a file or stdout * @param {string} file filepath to use as output */ -module.exports = async function ({ file: filePath, pretty }) { +module.exports = async ({ file: filePath, pretty }) => { const output = filePath ? fs.createWriteStream(filePath) : process.stdout; const appContext = await strapi.compile(); @@ -21,7 +21,7 @@ module.exports = async function ({ file: filePath, pretty }) { const pageCount = Math.ceil(count / CHUNK_SIZE); - for (let page = 0; page < pageCount; page++) { + for (let page = 0; page < pageCount; page += 1) { const results = await app .query('strapi::core-store') .findMany({ limit: CHUNK_SIZE, offset: page * CHUNK_SIZE, orderBy: 'key' }); diff --git a/packages/core/strapi/lib/core-api/controller/transform.js b/packages/core/strapi/lib/core-api/controller/transform.js index b7756bb64d..2ba4e2b155 100644 --- a/packages/core/strapi/lib/core-api/controller/transform.js +++ b/packages/core/strapi/lib/core-api/controller/transform.js @@ -56,7 +56,7 @@ const transformEntry = (entry, type) => { const attributeValues = {}; - for (const key in properties) { + for (const key of Object.keys(properties)) { const property = properties[key]; const attribute = type && type.attributes[key]; diff --git a/packages/core/strapi/lib/core/loaders/apis.js b/packages/core/strapi/lib/core/loaders/apis.js index 91a2b53839..72a0457cb3 100644 --- a/packages/core/strapi/lib/core/loaders/apis.js +++ b/packages/core/strapi/lib/core/loaders/apis.js @@ -40,7 +40,7 @@ module.exports = async (strapi) => { validateContentTypesUnicity(apis); - for (const apiName in apis) { + for (const apiName of Object.keys(apis)) { strapi.container.get('apis').add(apiName, apis[apiName]); } }; diff --git a/packages/core/strapi/lib/core/loaders/plugins/get-enabled-plugins.js b/packages/core/strapi/lib/core/loaders/plugins/get-enabled-plugins.js index 682cdd6a33..83b997f5ff 100644 --- a/packages/core/strapi/lib/core/loaders/plugins/get-enabled-plugins.js +++ b/packages/core/strapi/lib/core/loaders/plugins/get-enabled-plugins.js @@ -59,7 +59,9 @@ const getEnabledPlugins = async (strapi) => { } const installedPlugins = {}; - for (const dep in strapi.config.get('info.dependencies', {})) { + const dependencies = strapi.config.get('info.dependencies', {}); + + for (const dep of Object.keys(dependencies)) { const packagePath = join(dep, 'package.json'); let packageInfo; try { diff --git a/packages/core/strapi/lib/core/loaders/plugins/index.js b/packages/core/strapi/lib/core/loaders/plugins/index.js index c52fd9c0b3..d7b1b8e39b 100644 --- a/packages/core/strapi/lib/core/loaders/plugins/index.js +++ b/packages/core/strapi/lib/core/loaders/plugins/index.js @@ -34,10 +34,10 @@ const applyUserExtension = async (plugins) => { const extendedSchemas = await loadFiles(extensionsDir, '**/content-types/**/schema.json'); const strapiServers = await loadFiles(extensionsDir, '**/strapi-server.js'); - for (const pluginName in plugins) { + for (const pluginName of Object.keys(plugins)) { const plugin = plugins[pluginName]; // first: load json schema - for (const ctName in plugin.contentTypes) { + for (const ctName of Object.keys(plugin.contentTypes)) { const extendedSchema = get([pluginName, 'content-types', ctName, 'schema'], extendedSchemas); if (extendedSchema) { plugin.contentTypes[ctName].schema = { @@ -57,7 +57,7 @@ const applyUserExtension = async (plugins) => { const applyUserConfig = async (plugins) => { const userPluginsConfig = await getUserPluginsConfig(); - for (const pluginName in plugins) { + for (const pluginName of Object.keys(plugins)) { const plugin = plugins[pluginName]; const userPluginConfig = getOr({}, `${pluginName}.config`, userPluginsConfig); const defaultConfig = @@ -82,7 +82,7 @@ const loadPlugins = async (strapi) => { strapi.config.set('enabledPlugins', enabledPlugins); - for (const pluginName in enabledPlugins) { + for (const pluginName of Object.keys(enabledPlugins)) { const enabledPlugin = enabledPlugins[pluginName]; const serverEntrypointPath = join(enabledPlugin.pathToPlugin, 'strapi-server.js'); @@ -100,7 +100,7 @@ const loadPlugins = async (strapi) => { await applyUserConfig(plugins); await applyUserExtension(plugins); - for (const pluginName in plugins) { + for (const pluginName of Object.keys(plugins)) { strapi.container.get('plugins').add(pluginName, plugins[pluginName]); } }; diff --git a/packages/core/strapi/lib/core/registries/content-types.js b/packages/core/strapi/lib/core/registries/content-types.js index e1b5164fde..c523d50aa4 100644 --- a/packages/core/strapi/lib/core/registries/content-types.js +++ b/packages/core/strapi/lib/core/registries/content-types.js @@ -5,7 +5,7 @@ const { createContentType } = require('../domain/content-type'); const { addNamespace, hasNamespace } = require('../utils'); const validateKeySameToSingularName = (contentTypes) => { - for (const ctName in contentTypes) { + for (const ctName of Object.keys(contentTypes)) { const contentType = contentTypes[ctName]; if (ctName !== contentType.schema.info.singularName) { @@ -63,7 +63,7 @@ const contentTypesRegistry = () => { add(namespace, newContentTypes) { validateKeySameToSingularName(newContentTypes); - for (const rawCtName in newContentTypes) { + for (const rawCtName of Object.keys(newContentTypes)) { const uid = addNamespace(rawCtName, namespace); if (has(uid, contentTypes)) { diff --git a/packages/core/strapi/lib/core/registries/controllers.js b/packages/core/strapi/lib/core/registries/controllers.js index 47d965c1ae..f449ed8b35 100644 --- a/packages/core/strapi/lib/core/registries/controllers.js +++ b/packages/core/strapi/lib/core/registries/controllers.js @@ -48,7 +48,7 @@ const controllersRegistry = () => { const filteredControllers = pickBy((_, uid) => hasNamespace(uid, namespace))(controllers); const map = {}; - for (const uid in filteredControllers) { + for (const uid of Object.keys(filteredControllers)) { Object.defineProperty(map, uid, { enumerable: true, get: () => { @@ -78,7 +78,7 @@ const controllersRegistry = () => { * @returns */ add(namespace, newControllers) { - for (const controllerName in newControllers) { + for (const controllerName of Object.keys(newControllers)) { const controller = newControllers[controllerName]; const uid = addNamespace(controllerName, namespace); diff --git a/packages/core/strapi/lib/core/registries/hooks.js b/packages/core/strapi/lib/core/registries/hooks.js index 413e431b73..a62c68cf7f 100644 --- a/packages/core/strapi/lib/core/registries/hooks.js +++ b/packages/core/strapi/lib/core/registries/hooks.js @@ -54,7 +54,7 @@ const hooksRegistry = () => { * @returns */ add(namespace, hooks) { - for (const hookName in hooks) { + for (const hookName of Object.keys(hooks)) { const hook = hooks[hookName]; const uid = addNamespace(hookName, namespace); diff --git a/packages/core/strapi/lib/core/registries/middlewares.js b/packages/core/strapi/lib/core/registries/middlewares.js index 584dc57f4c..24097195a4 100644 --- a/packages/core/strapi/lib/core/registries/middlewares.js +++ b/packages/core/strapi/lib/core/registries/middlewares.js @@ -55,7 +55,7 @@ const middlewaresRegistry = () => { * @returns */ add(namespace, rawMiddlewares) { - for (const middlewareName in rawMiddlewares) { + for (const middlewareName of Object.keys(rawMiddlewares)) { const middleware = rawMiddlewares[middlewareName]; const uid = addNamespace(middlewareName, namespace); diff --git a/packages/core/strapi/lib/core/registries/policies.js b/packages/core/strapi/lib/core/registries/policies.js index bd7dc840a8..d185fb85b5 100644 --- a/packages/core/strapi/lib/core/registries/policies.js +++ b/packages/core/strapi/lib/core/registries/policies.js @@ -55,7 +55,7 @@ const policiesRegistry = () => { * @returns */ add(namespace, newPolicies) { - for (const policyName in newPolicies) { + for (const policyName of Object.keys(newPolicies)) { const policy = newPolicies[policyName]; const uid = addNamespace(policyName, namespace); diff --git a/packages/core/strapi/lib/core/registries/services.js b/packages/core/strapi/lib/core/registries/services.js index 4d0829eb14..4e8a8bd75c 100644 --- a/packages/core/strapi/lib/core/registries/services.js +++ b/packages/core/strapi/lib/core/registries/services.js @@ -48,7 +48,7 @@ const servicesRegistry = (strapi) => { // create lazy accessor to avoid instantiating the services; const map = {}; - for (const uid in filteredServices) { + for (const uid of Object.keys(filteredServices)) { Object.defineProperty(map, uid, { enumerable: true, get: () => { @@ -78,7 +78,7 @@ const servicesRegistry = (strapi) => { * @returns */ add(namespace, newServices) { - for (const serviceName in newServices) { + for (const serviceName of Object.keys(newServices)) { const service = newServices[serviceName]; const uid = addNamespace(serviceName, namespace); diff --git a/packages/core/strapi/lib/services/cron.js b/packages/core/strapi/lib/services/cron.js index 0364224b12..4b1f6136cd 100644 --- a/packages/core/strapi/lib/services/cron.js +++ b/packages/core/strapi/lib/services/cron.js @@ -9,7 +9,7 @@ const createCronService = () => { return { add(tasks = {}) { - for (const taskExpression in tasks) { + for (const taskExpression of Object.keys(tasks)) { const taskValue = tasks[taskExpression]; let fn; diff --git a/packages/core/strapi/lib/services/entity-service/components.js b/packages/core/strapi/lib/services/entity-service/components.js index 17cd90c823..0b29b897e9 100644 --- a/packages/core/strapi/lib/services/entity-service/components.js +++ b/packages/core/strapi/lib/services/entity-service/components.js @@ -22,7 +22,7 @@ const createComponents = async (uid, data) => { const componentBody = {}; - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (!has(attributeName, data) || !contentTypesUtils.isComponentAttribute(attribute)) { @@ -122,7 +122,7 @@ const updateComponents = async (uid, entityToUpdate, data) => { const componentBody = {}; - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (!has(attributeName, data)) { @@ -277,7 +277,7 @@ const deleteOldDZComponents = async (uid, entityToUpdate, attributeName, dynamic const deleteComponents = async (uid, entityToDelete) => { const { attributes } = strapi.getModel(uid); - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (attribute.type === 'component') { diff --git a/packages/core/strapi/lib/services/entity-validator/index.js b/packages/core/strapi/lib/services/entity-validator/index.js index ddd6eb6232..9473366198 100644 --- a/packages/core/strapi/lib/services/entity-validator/index.js +++ b/packages/core/strapi/lib/services/entity-validator/index.js @@ -14,51 +14,56 @@ const { isMediaAttribute, isScalarAttribute, getWritableAttributes } = strapiUti const { ValidationError } = strapiUtils.errors; const addMinMax = (validator, { attr, updatedAttribute }) => { + let nextValidator = validator; + if ( Number.isInteger(attr.min) && (attr.required || (Array.isArray(updatedAttribute.value) && updatedAttribute.value.length > 0)) ) { - validator = validator.min(attr.min); + nextValidator = nextValidator.min(attr.min); } if (Number.isInteger(attr.max)) { - validator = validator.max(attr.max); + nextValidator = nextValidator.max(attr.max); } - return validator; + return nextValidator; }; -const addRequiredValidation = - (createOrUpdate) => - (validator, { attr: { required } }) => { +const addRequiredValidation = (createOrUpdate) => { + return (validator, { attr: { required } }) => { + let nextValidator = validator; if (required) { if (createOrUpdate === 'creation') { - validator = validator.notNil(); + nextValidator = nextValidator.notNil(); } else if (createOrUpdate === 'update') { - validator = validator.notNull(); + nextValidator = nextValidator.notNull(); } } else { - validator = validator.nullable(); + nextValidator = nextValidator.nullable(); } - return validator; + return nextValidator; }; +}; + +const addDefault = (createOrUpdate) => { + return (validator, { attr }) => { + let nextValidator = validator; -const addDefault = - (createOrUpdate) => - (validator, { attr }) => { if (createOrUpdate === 'creation') { if ( ((attr.type === 'component' && attr.repeatable) || attr.type === 'dynamiczone') && !attr.required ) { - validator = validator.default([]); + nextValidator = nextValidator.default([]); } else { - validator = validator.default(attr.default); + nextValidator = nextValidator.default(attr.default); } } else { - validator = validator.default(undefined); + nextValidator = nextValidator.default(undefined); } - return validator; + return nextValidator; }; +}; const preventCast = (validator) => validator.transform((val, originalVal) => originalVal); diff --git a/packages/core/strapi/lib/services/metrics/__tests__/middleware.test.js b/packages/core/strapi/lib/services/metrics/__tests__/middleware.test.js index 35f6a7321f..7ae9744de8 100644 --- a/packages/core/strapi/lib/services/metrics/__tests__/middleware.test.js +++ b/packages/core/strapi/lib/services/metrics/__tests__/middleware.test.js @@ -43,7 +43,7 @@ describe('Metrics middleware', () => { const sendEvent = jest.fn(); const middleware = createMiddleware({ sendEvent }); - for (let i = 0; i < 2000; i++) { + for (let i = 0; i < 2000; i += 1) { await middleware( { request: { diff --git a/packages/core/strapi/lib/services/metrics/middleware.js b/packages/core/strapi/lib/services/metrics/middleware.js index a8c6d1519f..7d9e7047e8 100644 --- a/packages/core/strapi/lib/services/metrics/middleware.js +++ b/packages/core/strapi/lib/services/metrics/middleware.js @@ -22,7 +22,7 @@ const createMiddleware = ({ sendEvent }) => { sendEvent('didReceiveRequest', { url: ctx.request.url }); // Increase counter. - _state.counter++; + _state.counter += 1; } } diff --git a/packages/core/strapi/lib/services/server/register-routes.js b/packages/core/strapi/lib/services/server/register-routes.js index 75c6f8f75d..06a14a2262 100644 --- a/packages/core/strapi/lib/services/server/register-routes.js +++ b/packages/core/strapi/lib/services/server/register-routes.js @@ -50,7 +50,7 @@ const registerAdminRoutes = (strapi) => { * @param {import('../../').Strapi} strapi */ const registerPluginRoutes = (strapi) => { - for (const pluginName in strapi.plugins) { + for (const pluginName of Object.keys(strapi.plugins)) { const plugin = strapi.plugins[pluginName]; const generateRouteScope = createRouteScopeGenerator(`plugin::${pluginName}`); @@ -86,7 +86,7 @@ const registerPluginRoutes = (strapi) => { * @param {import('../../').Strapi} strapi */ const registerAPIRoutes = (strapi) => { - for (const apiName in strapi.api) { + for (const apiName of Object.keys(strapi.api)) { const api = strapi.api[apiName]; const generateRouteScope = createRouteScopeGenerator(`api::${apiName}`); diff --git a/packages/core/strapi/lib/services/utils/upload-files.js b/packages/core/strapi/lib/services/utils/upload-files.js index aab1a1f8df..f199c80f45 100644 --- a/packages/core/strapi/lib/services/utils/upload-files.js +++ b/packages/core/strapi/lib/services/utils/upload-files.js @@ -27,7 +27,7 @@ module.exports = async (uid, entity, files) => { let tmpModel = modelDef; let modelUID = uid; - for (let i = 0; i < path.length; i++) { + for (let i = 0; i < path.length; i += 1) { if (!tmpModel) return {}; const part = path[i]; const attr = tmpModel.attributes[part]; diff --git a/packages/core/strapi/lib/services/worker-queue.js b/packages/core/strapi/lib/services/worker-queue.js index bece4f70b8..2a0a2bc45e 100644 --- a/packages/core/strapi/lib/services/worker-queue.js +++ b/packages/core/strapi/lib/services/worker-queue.js @@ -26,7 +26,7 @@ module.exports = class WorkerQueue { enqueue(payload) { debug('Enqueue event in worker queue'); if (this.running < this.concurrency) { - this.running++; + this.running += 1; this.execute(payload); } else { this.queue.unshift(payload); @@ -40,7 +40,7 @@ module.exports = class WorkerQueue { if (payload) { this.execute(payload); } else { - this.running--; + this.running -= 1; } } diff --git a/packages/core/strapi/lib/utils/addSlash.js b/packages/core/strapi/lib/utils/addSlash.js index a25acbc256..e3ef826d86 100644 --- a/packages/core/strapi/lib/utils/addSlash.js +++ b/packages/core/strapi/lib/utils/addSlash.js @@ -1,10 +1,11 @@ 'use strict'; module.exports = (path) => { - if (typeof path !== 'string') throw new Error('admin.url must be a string'); - if (path === '' || path === '/') return '/'; + let tmpPath = path; + if (typeof tmpPath !== 'string') throw new Error('admin.url must be a string'); + if (tmpPath === '' || tmpPath === '/') return '/'; - if (path[0] != '/') path = `/${path}`; - if (path[path.length - 1] != '/') path += '/'; - return path; + if (tmpPath[0] !== '/') tmpPath = `/${tmpPath}`; + if (tmpPath[tmpPath.length - 1] !== '/') tmpPath += '/'; + return tmpPath; }; From 70b6966458753de17bba8696550c3b4df928898a Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 5 Sep 2022 19:44:58 +0200 Subject: [PATCH 12/13] Fix eslint database --- packages/core/database/lib/entity-manager.js | 8 ++++---- packages/core/database/lib/lifecycles/index.js | 2 +- packages/core/database/lib/query/helpers/join.js | 2 +- packages/core/database/lib/query/helpers/populate.js | 10 +++++----- packages/core/database/lib/query/helpers/transform.js | 2 +- packages/core/database/lib/query/helpers/where.js | 4 ++-- packages/core/database/lib/query/query-builder.js | 8 +++++++- packages/core/database/lib/schema/schema.js | 2 +- 8 files changed, 22 insertions(+), 16 deletions(-) diff --git a/packages/core/database/lib/entity-manager.js b/packages/core/database/lib/entity-manager.js index 7d492e4b71..13ab1564b4 100644 --- a/packages/core/database/lib/entity-manager.js +++ b/packages/core/database/lib/entity-manager.js @@ -34,7 +34,7 @@ const processData = (metadata, data = {}, { withDefaults = false } = {}) => { const obj = {}; - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (types.isScalar(attribute.type)) { @@ -333,7 +333,7 @@ const createEntityManager = (db) => { async attachRelations(uid, id, data) { const { attributes } = db.metadata.get(uid); - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; const isValidLink = _.has(attributeName, data) && !_.isNil(data[attributeName]); @@ -487,7 +487,7 @@ const createEntityManager = (db) => { async updateRelations(uid, id, data) { const { attributes } = db.metadata.get(uid); - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (attribute.type !== 'relation' || !_.has(attributeName, data)) { @@ -667,7 +667,7 @@ const createEntityManager = (db) => { async deleteRelations(uid, id) { const { attributes } = db.metadata.get(uid); - for (const attributeName in attributes) { + for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName]; if (attribute.type !== 'relation') { diff --git a/packages/core/database/lib/lifecycles/index.js b/packages/core/database/lib/lifecycles/index.js index ce3a836ad3..b4f2061ec6 100644 --- a/packages/core/database/lib/lifecycles/index.js +++ b/packages/core/database/lib/lifecycles/index.js @@ -54,7 +54,7 @@ const createLifecyclesProvider = (db) => { * @param {Map} states */ async run(action, uid, properties, states = new Map()) { - for (let i = 0; i < subscribers.length; i++) { + for (let i = 0; i < subscribers.length; i += 1) { const subscriber = subscribers[i]; if (typeof subscriber === 'function') { const state = states.get(subscriber) || {}; diff --git a/packages/core/database/lib/query/helpers/join.js b/packages/core/database/lib/query/helpers/join.js index daf0f075a3..d8f32d75ac 100644 --- a/packages/core/database/lib/query/helpers/join.js +++ b/packages/core/database/lib/query/helpers/join.js @@ -71,7 +71,7 @@ const applyJoin = (qb, join) => { inner.on(`${rootTable}.${rootColumn}`, `${alias}.${referencedColumn}`); if (on) { - for (const key in on) { + for (const key of Object.keys(on)) { inner.onVal(`${alias}.${key}`, on[key]); } } diff --git a/packages/core/database/lib/query/helpers/populate.js b/packages/core/database/lib/query/helpers/populate.js index c5f01fabe2..4c4f23cf9a 100644 --- a/packages/core/database/lib/query/helpers/populate.js +++ b/packages/core/database/lib/query/helpers/populate.js @@ -8,7 +8,7 @@ const { fromRow } = require('./transform'); const getRootLevelPopulate = (meta) => { const populate = {}; - for (const attributeName in meta.attributes) { + for (const attributeName of Object.keys(meta.attributes)) { const attribute = meta.attributes[attributeName]; if (attribute.type === 'relation') { populate[attributeName] = true; @@ -72,7 +72,7 @@ const processPopulate = (populate, ctx) => { } const finalPopulate = {}; - for (const key in populateMap) { + for (const key of Object.keys(populateMap)) { const attribute = meta.attributes[key]; if (!attribute) { @@ -119,7 +119,7 @@ const applyPopulate = async (results, populate, ctx) => { return results; } - for (const key in populate) { + for (const key of Object.keys(populate)) { const attribute = meta.attributes[key]; const targetMeta = db.metadata.get(attribute.target); @@ -540,7 +540,7 @@ const applyPopulate = async (results, populate, ctx) => { }, {}); const map = {}; - for (const type in idsByType) { + for (const type of Object.keys(idsByType)) { const ids = idsByType[type]; // type was removed but still in morph relation @@ -604,7 +604,7 @@ const applyPopulate = async (results, populate, ctx) => { }, {}); const map = {}; - for (const type in idsByType) { + for (const type of Object.keys(idsByType)) { const ids = idsByType[type]; // type was removed but still in morph relation diff --git a/packages/core/database/lib/query/helpers/transform.js b/packages/core/database/lib/query/helpers/transform.js index ceef64762a..4ac27a62e5 100644 --- a/packages/core/database/lib/query/helpers/transform.js +++ b/packages/core/database/lib/query/helpers/transform.js @@ -53,7 +53,7 @@ const toRow = (meta, data = {}) => { const { attributes } = meta; - for (const key in data) { + for (const key of Object.keys(data)) { const attribute = attributes[key]; if (!attribute || attribute.columnName === key) { diff --git a/packages/core/database/lib/query/helpers/where.js b/packages/core/database/lib/query/helpers/where.js index e0b74c48df..70a7d5b96e 100644 --- a/packages/core/database/lib/query/helpers/where.js +++ b/packages/core/database/lib/query/helpers/where.js @@ -76,7 +76,7 @@ const processAttributeWhere = (attribute, where, operator = '$eq') => { const filters = {}; - for (const key in where) { + for (const key of Object.keys(where)) { const value = where[key]; if (!isOperator(key)) { @@ -119,7 +119,7 @@ const processWhere = (where, ctx) => { const filters = {}; // for each key in where - for (const key in where) { + for (const key of Object.keys(where)) { const value = where[key]; // if operator $and $or then loop over them diff --git a/packages/core/database/lib/query/query-builder.js b/packages/core/database/lib/query/query-builder.js index c7bb9e13fd..b94e6da506 100644 --- a/packages/core/database/lib/query/query-builder.js +++ b/packages/core/database/lib/query/query-builder.js @@ -27,7 +27,13 @@ const createQueryBuilder = (uid, db) => { }; let counter = 0; - const getAlias = () => `t${counter++}`; + const getAlias = () => { + const alias = `t${counter}`; + + counter += 1; + + return alias; + }; return { alias: getAlias(), diff --git a/packages/core/database/lib/schema/schema.js b/packages/core/database/lib/schema/schema.js index be8ee5728a..643d7b7e8a 100644 --- a/packages/core/database/lib/schema/schema.js +++ b/packages/core/database/lib/schema/schema.js @@ -25,7 +25,7 @@ const createTable = (meta) => { columns: [], }; - for (const key in meta.attributes) { + for (const key of Object.keys(meta.attributes)) { const attribute = meta.attributes[key]; if (types.isRelation(attribute.type)) { From 961d535ea98dfa837e06d2e5d37c1a3045a918dc Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Tue, 6 Sep 2022 09:07:01 +0200 Subject: [PATCH 13/13] Fix for in working with undefined --- .../server/tests/admin-permissions-conditions.test.e2e.js | 2 +- packages/core/strapi/lib/core/registries/middlewares.js | 2 +- .../core/strapi/lib/services/entity-service/components.js | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js b/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js index 3e08b4c92d..fcdfd12560 100644 --- a/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js +++ b/packages/core/admin/server/tests/admin-permissions-conditions.test.e2e.js @@ -84,7 +84,7 @@ if (edition === 'EE') { // Create users with the new role & create associated auth requests const users = []; - for (let i = 1; i < localTestData.users.length; i += 1) { + for (let i = 0; i < localTestData.users.length; i += 1) { const userFixture = localTestData.users[i]; const userAttributes = { ...userFixture, diff --git a/packages/core/strapi/lib/core/registries/middlewares.js b/packages/core/strapi/lib/core/registries/middlewares.js index 24097195a4..5b47561220 100644 --- a/packages/core/strapi/lib/core/registries/middlewares.js +++ b/packages/core/strapi/lib/core/registries/middlewares.js @@ -54,7 +54,7 @@ const middlewaresRegistry = () => { * @param {{ [key: string]: Middleware }} newMiddlewares * @returns */ - add(namespace, rawMiddlewares) { + add(namespace, rawMiddlewares = {}) { for (const middlewareName of Object.keys(rawMiddlewares)) { const middleware = rawMiddlewares[middlewareName]; const uid = addNamespace(middlewareName, namespace); diff --git a/packages/core/strapi/lib/services/entity-service/components.js b/packages/core/strapi/lib/services/entity-service/components.js index 0b29b897e9..4244feaa95 100644 --- a/packages/core/strapi/lib/services/entity-service/components.js +++ b/packages/core/strapi/lib/services/entity-service/components.js @@ -18,7 +18,7 @@ const omitComponentData = (contentType, data) => { // NOTE: we could generalize the logic to allow CRUD of relation directly in the DB layer const createComponents = async (uid, data) => { - const { attributes } = strapi.getModel(uid); + const { attributes = {} } = strapi.getModel(uid); const componentBody = {}; @@ -118,7 +118,7 @@ const getComponents = async (uid, entity) => { create or update */ const updateComponents = async (uid, entityToUpdate, data) => { - const { attributes } = strapi.getModel(uid); + const { attributes = {} } = strapi.getModel(uid); const componentBody = {}; @@ -275,7 +275,7 @@ const deleteOldDZComponents = async (uid, entityToUpdate, attributeName, dynamic }; const deleteComponents = async (uid, entityToDelete) => { - const { attributes } = strapi.getModel(uid); + const { attributes = {} } = strapi.getModel(uid); for (const attributeName of Object.keys(attributes)) { const attribute = attributes[attributeName];