mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Check for valid type
This commit is contained in:
parent
46ff49f66e
commit
05e9b74002
@ -1,4 +1,8 @@
|
||||
'use strict';
|
||||
const { DEFAULT_TYPES } = require('../constants');
|
||||
|
||||
const notAllowedTypes = ['component', 'relation', 'dynamiczone', 'media'];
|
||||
const allowedTypes = DEFAULT_TYPES.filter(type => !notAllowedTypes.includes(type));
|
||||
|
||||
/**
|
||||
* @description
|
||||
@ -8,9 +12,9 @@
|
||||
const convertCustomFieldType = attributes => {
|
||||
Object.values(attributes).forEach(attribute => {
|
||||
if (attribute.customField) {
|
||||
if (['component', 'relation', 'dynamiczone'].includes(attribute.type)) {
|
||||
// When the registered custom fiel is using an invalid strapi type
|
||||
throw new Error(`Type: ${attribute.type} is not a valid Custom Field type`);
|
||||
if (!allowedTypes.includes(attribute.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`);
|
||||
}
|
||||
// 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user