validate compo

This commit is contained in:
Alexandre Bodin 2021-07-08 22:50:24 +02:00
parent 6d78f94a54
commit d48eaa0d1f
4 changed files with 34 additions and 32 deletions

View File

@ -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",

View File

@ -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;

View File

@ -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)) {

View File

@ -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 => {