controller-util

1.0.32 • Public • Published

ws: a node.js websocket library

sequelize-util is a simple way to organice your sequelice models, connections...

Installing

npm install --save controller-util

Starting the controllers

var ControllerUtil = require('controller-util');

/**
 * CREATE INSTANCE OF CONTROLLER
 *  PRODUCTION & DEVELLOPER...
 **/
var controllers = ControllerUtil({
	controllers: "your path directory where file models are." (use the full path).
}, "example-prod");

/*
 *  INIT THE CONTROLLERS WITH NEEDED
 *	 baseController.init()
 */
controllers.init('prod');
//baseController file is needed, to be executed 

Base Controller

Create the baseController file and put it in folder with all controller files. filename: baseController.js

function baseController() {
	var shareObject = {
		value: 'One for all, all for one.'
	};

	function init(env = 'prod') {
		this._ENV = env;
		this.shareObject = shareObject;
	}

	this.init = init;
}
module.exports = baseController;

Your first controller

Lest create persons controller filename: persons.js

function persons() {
	var shareObject = this.shareObject;
	var store = [];

	function create(name, lastname) {
		var person = {
			name,
			lastname,
			motto: shareObject.value
		}
		store.push(person);
		return person;
	}
	/*
	 *	SOME ASYNC WORK
	 */
	function savePerson(person) {
		return new Promise((resolve, reject)=>{
			//YOUR ASYNC TASK
			resolve('Done :)', person);
		});
	}

	this.create = create;
	this.save = save;
}
module.exports = persons;

Requiring the colection of controllers

var controllers = require('controller-util').getSchema("example-dev");

controllers.persons.create('Juan','Perez').then(person=>{
	console.log(person);
}).catch(err=>{
	console.log(err);
});

controllers.persons.save(person).then(person=>{
	console.log(person);
}).catch(err=>{
	console.log(err);
});

Package Sidebar

Install

npm i controller-util

Weekly Downloads

1

Version

1.0.32

License

ISC

Last publish

Collaborators

  • gabryk