validates missing useAsTitle
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
9
src/errors/MissingUseAsTitle.js
Normal file
9
src/errors/MissingUseAsTitle.js
Normal 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;
|
||||
Reference in New Issue
Block a user