validates missing useAsTitle

This commit is contained in:
James
2020-01-24 19:22:32 -05:00
parent fdd0225988
commit 7be292cd81
2 changed files with 17 additions and 1 deletions

View File

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

View File

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