From d48eaa0d1fd57a5ec93db8c1ca9e3d5209b360e7 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Thu, 8 Jul 2021 22:50:24 +0200 Subject: [PATCH] validate compo --- .../core/content-type-builder/package.json | 2 +- .../strapi/lib/services/entity-service.js | 61 ++++++++++--------- .../lib/services/entity-validator/index.js | 1 + packages/core/utils/lib/content-types.js | 2 +- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/packages/core/content-type-builder/package.json b/packages/core/content-type-builder/package.json index 111467f1fd..2a424b5543 100644 --- a/packages/core/content-type-builder/package.json +++ b/packages/core/content-type-builder/package.json @@ -33,7 +33,7 @@ "redux": "^4.0.1", "redux-immutable": "^4.0.0", "reselect": "^4.0.0", - "yup": "^0.27.0" + "yup": "^0.32.9" }, "author": { "name": "Strapi team", diff --git a/packages/core/strapi/lib/services/entity-service.js b/packages/core/strapi/lib/services/entity-service.js index 878d1f5e6c..0a16289db5 100644 --- a/packages/core/strapi/lib/services/entity-service.js +++ b/packages/core/strapi/lib/services/entity-service.js @@ -405,26 +405,27 @@ const createComponents = async (uid, data) => { continue; } - if (attribute.type === 'dynamiczone') { - const dynamiczoneValues = data[attributeName]; + // if (attribute.type === 'dynamiczone') { - if (!Array.isArray(dynamiczoneValues)) { - throw new Error('Expected an array to create repeatable component'); - } + // const dynamiczoneValues = data[attributeName]; - const components = await Promise.all( - dynamiczoneValues.map(value => { - return strapi.query(value.__component).create({ data: value }); - }) - ); + // if (!Array.isArray(dynamiczoneValues)) { + // throw new Error('Expected an array to create repeatable component'); + // } - componentBody[attributeName] = components.map(({ id }, idx) => { - // TODO: add & support pivot data in DB - return id; - }); + // const components = await Promise.all( + // dynamiczoneValues.map(value => { + // return strapi.query(value.__component).create({ data: value }); + // }) + // ); - continue; - } + // componentBody[attributeName] = components.map(({ id }, idx) => { + // // TODO: add & support pivot data in DB + // return id; + // }); + + // continue; + // } } return componentBody; @@ -491,24 +492,24 @@ const updateComponents = async (uid, entityToUpdate, data) => { continue; } - if (attribute.type === 'dynamiczone') { - const dynamiczoneValues = data[attributeName]; + // if (attribute.type === 'dynamiczone') { + // const dynamiczoneValues = data[attributeName]; - if (!Array.isArray(dynamiczoneValues)) { - throw new Error('Expected an array to create repeatable component'); - } + // if (!Array.isArray(dynamiczoneValues)) { + // throw new Error('Expected an array to create repeatable component'); + // } - const components = await Promise.all( - dynamiczoneValues.map(value => updateOrCreateComponent(value.__component, value)) - ); + // const components = await Promise.all( + // dynamiczoneValues.map(value => updateOrCreateComponent(value.__component, value)) + // ); - componentBody[attributeName] = components.map(({ id }, idx) => { - // TODO: add & support pivot data in DB - return id; - }); + // componentBody[attributeName] = components.map(({ id }, idx) => { + // // TODO: add & support pivot data in DB + // return id; + // }); - continue; - } + // continue; + // } } return componentBody; diff --git a/packages/core/strapi/lib/services/entity-validator/index.js b/packages/core/strapi/lib/services/entity-validator/index.js index d7547fea38..fe6bdd63b2 100644 --- a/packages/core/strapi/lib/services/entity-validator/index.js +++ b/packages/core/strapi/lib/services/entity-validator/index.js @@ -134,6 +134,7 @@ const createScalarAttributeValidator = createOrUpdate => (attr, { isDraft }) => const createAttributeValidator = createOrUpdate => (attr, data, { isDraft }) => { let validator; + if (isMediaAttribute(attr)) { validator = yup.mixed(); } else if (isScalarAttribute(attr)) { diff --git a/packages/core/utils/lib/content-types.js b/packages/core/utils/lib/content-types.js index 1b9941dc25..7a941bdf63 100644 --- a/packages/core/utils/lib/content-types.js +++ b/packages/core/utils/lib/content-types.js @@ -94,7 +94,7 @@ const isPrivateAttribute = (model = {}, attributeName) => { }; const isScalarAttribute = attribute => { - return ['component', 'relation', 'dynamiczone'].includes(attribute.type); + return !['component', 'relation', 'dynamiczone'].includes(attribute.type); }; const isMediaAttribute = attr => {