diff --git a/src/packages/application/errors/controller-missing.js b/src/packages/application/errors/controller-missing.js new file mode 100644 index 00000000..6d21d12b --- /dev/null +++ b/src/packages/application/errors/controller-missing.js @@ -0,0 +1,7 @@ +class ControllerMissingError extends Error { + constructor(resource) { + return super(`Could not resolve controller by name '${resource}'`); + } +} + +export default ControllerMissingError; diff --git a/src/packages/application/errors/index.js b/src/packages/application/errors/index.js new file mode 100644 index 00000000..7703ee37 --- /dev/null +++ b/src/packages/application/errors/index.js @@ -0,0 +1,2 @@ +export ControllerMissingError from './controller-missing'; +export SerializerMissingError from './serializer-missing'; diff --git a/src/packages/application/errors/serializer-missing.js b/src/packages/application/errors/serializer-missing.js new file mode 100644 index 00000000..7afeb761 --- /dev/null +++ b/src/packages/application/errors/serializer-missing.js @@ -0,0 +1,7 @@ +class SerializerMissingError extends Error { + constructor(resource) { + return super(`Could not resolve serializer by name '${resource}'`); + } +} + +export default SerializerMissingError; diff --git a/src/packages/application/index.js b/src/packages/application/index.js index b319dd84..50c1357f 100644 --- a/src/packages/application/index.js +++ b/src/packages/application/index.js @@ -1,6 +1,6 @@ import Promise from 'bluebird'; import cluster from 'cluster'; -import { singularize } from 'inflection'; +import { pluralize, singularize } from 'inflection'; import Server from '../server'; import Router from '../router'; @@ -8,6 +8,11 @@ import Database from '../database'; import loader from '../loader'; +import { + ControllerMissingError, + SerializerMissingError +} from './errors'; + const { defineProperties } = Object; const { env: { PWD, PORT } } = process; @@ -115,6 +120,18 @@ class Application { await store.define(models); + models.forEach((model, name) => { + const resource = pluralize(name); + + if (!controllers.get(resource)) { + throw new ControllerMissingError(resource); + } + + if (!serializers.get(resource)) { + throw new SerializerMissingError(resource); + } + }); + serializers.forEach((serializer, name) => { const model = models.get(singularize(name));