Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New FCC Models, Service, Controller, Module and Class layers #80

Merged
merged 7 commits into from
Jun 7, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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