Check for valid type

This commit is contained in:
Mark Kaylor 2022-08-03 09:30:33 +02:00
parent 46ff49f66e
commit 05e9b74002

View File

@ -1,4 +1,8 @@
'use strict'; 'use strict';
const { DEFAULT_TYPES } = require('../constants');
const notAllowedTypes = ['component', 'relation', 'dynamiczone', 'media'];
const allowedTypes = DEFAULT_TYPES.filter(type => !notAllowedTypes.includes(type));
/** /**
* @description * @description
@ -8,9 +12,9 @@
const convertCustomFieldType = attributes => { const convertCustomFieldType = attributes => {
Object.values(attributes).forEach(attribute => { Object.values(attributes).forEach(attribute => {
if (attribute.customField) { if (attribute.customField) {
if (['component', 'relation', 'dynamiczone'].includes(attribute.type)) { if (!allowedTypes.includes(attribute.type)) {
// When the registered custom fiel is using an invalid strapi type // When the custom field was registered with an invalid strapi type
throw new Error(`Type: ${attribute.type} is not a valid Custom Field type`); throw new Error(`Type: "${attribute.type}" is not a valid Custom Field type`);
} }
// Use the custom field uid sent from the admin to get its equivalent on the server // Use the custom field uid sent from the admin to get its equivalent on the server
// The getter will throw an error if the custom field is not found // The getter will throw an error if the custom field is not found