1.0.32 • Published 6 years ago

controller-util v1.0.32

Weekly downloads
1
License
ISC
Repository
-
Last release
6 years ago

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);
});
1.0.32

6 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago