datoit
Version:
An open source headless CMS solution to create and manage your own API. It provides a powerful dashboard and features to make your life easier. Databases supported: MongoDB, MySQL, MariaDB, PostgreSQL, SQLite
34 lines (25 loc) • 769 B
JavaScript
/**
* Core API
*/
;
const _ = require('lodash');
const createController = require('./controller');
const { createService } = require('./service');
/**
* Returns a service and a controller built based on the content type passed
*/
function createCoreApi({ api, model, strapi }) {
const { modelName } = model;
// find corresponding service and controller
const userService = _.get(api, ['services', modelName], {});
const userController = _.get(api, ['controllers', modelName], {});
const service = Object.assign(createService({ model, strapi }), userService);
const controller = Object.assign(createController({ service, model }), userController);
return {
service,
controller,
};
}
module.exports = {
createCoreApi,
};