Skip to content

Commit

Permalink
Merge pull request #80 from CleverStack/feature/modules-in-injector
Browse files Browse the repository at this point in the history
New FCC Models, Service, Controller, Module and Class layers
  • Loading branch information
pilsy committed Jun 7, 2014
2 parents f254812 + f3cbc5a commit 822e6d6
Show file tree
Hide file tree
Showing 13 changed files with 930 additions and 337 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ env.app.configure(function() {
env.app.use( cors( env.config.cors ) );
});

// Add some classes for simplicity
var classes = require( 'classes' );
injector.instance( 'Class', classes.Class );
injector.instance( 'Model', classes.Model );
injector.instance( 'Service', classes.Service );
injector.instance( 'Controller', classes.Controller );
injector.instance( 'Module', classes.Module );

// Load all the modules
env.moduleLoader.loadModules();

Expand Down
5 changes: 5 additions & 0 deletions lib/classes/Class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Class = require( 'uberclass' )
, EventEmitter = require( 'events' ).EventEmitter
, uberUtil = require( 'utils' ).uberUtil;

module.exports = Class.extend( uberUtil.inherits( {}, EventEmitter ) );
47 changes: 26 additions & 21 deletions lib/classes/Controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Controller = require('clever-controller');
var Controller = require( 'clever-controller' );

module.exports = Controller.extend(
/* @Static */
Expand All @@ -9,54 +9,59 @@ module.exports = Controller.extend(
{
listAction: function() {
if ( this.Class.service !== null ) {
var query = this.req.query;
var options = {};
if ( Object.keys( query ).length ) {
options.where = query;
}
this.Class.service.find( options )
.then( this.proxy( 'send' ) )
.fail( this.proxy( 'handleException' ) );
this.Class
.service
.findAll( this.req.query )
.then( this.proxy( 'handleServiceMessage' ) )
.catch( this.proxy( 'handleException' ) );
} else {
this.next();
}
},

getAction: function() {
if ( this.Class.service !== null ) {
this.Class.service.findById( this.req.params.id )
.then( this.proxy( 'send' ) )
.fail( this.proxy( 'handleException' ) );
this.Class
.service
.findById( this.req.params.id )
.then( this.proxy( 'handleServiceMessage' ) )
.catch( this.proxy( 'handleException' ) );
} else {
this.next();
}
},

postAction: function() {
if ( this.Class.service !== null ) {
this.Class.service.create( this.req.body )
.then( this.proxy( 'send' ) )
.fail( this.proxy( 'handleException' ) );
this.Class
.service
.create( this.req.body )
.then( this.proxy( 'handleServiceMessage' ) )
.catch( this.proxy( 'handleException' ) );
} else {
this.next();
}
},

putAction: function() {
if ( this.Class.service !== null ) {
this.Class.service.update( this.req.params.id, this.req.body )
.then( this.proxy( 'send' ) )
.fail( this.proxy( 'handleException' ) );
this.Class
.service
.update( this.req.params.id, this.req.body )
.then( this.proxy( 'handleServiceMessage' ) )
.catch( this.proxy( 'handleException' ) );
} else {
this.next();
}
},

deleteAction: function() {
if ( this.Class.service !== null ) {
this.Class.service.destroy( this.req.params.id )
.then( this.proxy( 'send' ) )
.fail( this.proxy( 'handleException' ) );
this.Class
.service
.destroy( this.req.params.id )
.then( this.proxy( 'handleServiceMessage' ) )
.catch( this.proxy( 'handleException' ) );
} else {
this.next();
}
Expand Down
Loading

0 comments on commit 822e6d6

Please sign in to comment.