33 lines
683 B
JavaScript
Raw Normal View History

2016-10-24 17:10:56 +02:00
'use strict';
/**
* Module dependencies
*/
const _ = require('lodash');
/**
* Find controller's location
*/
module.exports = (api, controller) => {
if (!_.isObject(api)) {
throw new Error('Should be an object');
}
if (_.isObject(controller) && controller.hasOwnProperty('identity')) {
2017-09-04 16:22:28 +02:00
controller = controller.identity.toLowerCase();
2016-10-24 17:10:56 +02:00
} else if (_.isString(controller)) {
controller = controller.toLowerCase();
} else {
throw new Error('Should be an object or a string');
}
const where = _.findKey(api, o => {
2018-05-03 18:13:22 +02:00
return _.get(o, `controllers.${controller}`);
2016-10-24 17:10:56 +02:00
});
// Return the API's name where the controller is located
return where;
};