diff --git a/src/collections/validate.js b/src/collections/validate.js index ecd6560979..1f19b79875 100644 --- a/src/collections/validate.js +++ b/src/collections/validate.js @@ -1,12 +1,19 @@ const errors = require('../errors'); -const { DuplicateCollection, MissingCollectionLabel } = errors; +const { DuplicateCollection, MissingCollectionLabel, MissingUseAsTitle } = errors; module.exports = function validateCollection(collection, collections) { if (!collection.labels.singular) { throw new MissingCollectionLabel(collection); } + const { useAsTitle } = collection; + const fieldToUseAsTitle = collection.fields.find(field => useAsTitle === field.name); + + if (!fieldToUseAsTitle) { + throw new MissingUseAsTitle(collection); + } + if (collections && collections[collection.labels.singular]) { throw new DuplicateCollection(collection); } diff --git a/src/errors/MissingUseAsTitle.js b/src/errors/MissingUseAsTitle.js new file mode 100644 index 0000000000..b2ec6d62d7 --- /dev/null +++ b/src/errors/MissingUseAsTitle.js @@ -0,0 +1,9 @@ +const APIError = require('./APIError'); + +class MissingUseAsTitle extends APIError { + constructor(collection) { + super(`${collection.labels.singular} collection is missing a useAsTitle property.`); + } +} + +module.exports = MissingCollectionLabel;