Skip to content

Commit

Permalink
Changed the way controllers access models.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanreid committed Mar 18, 2013
1 parent 99503f3 commit c2fa914
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
5 changes: 0 additions & 5 deletions webservice/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ var server = restify.createServer({
version: '0.2.0'
});

// Inject models to each controller
for(var key in controllers) {
controllers[key].models = models;
}

// Setup Restify server
require('./conf/restify.js')(restify, server);

Expand Down
13 changes: 4 additions & 9 deletions webservice/controllers/ideaTypes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

var IdeaTypesController = {
var IdeaType = require('../db.js').models.IdeaType;

list: function(req, res, next) {
module.exports = {

var IdeaType = IdeaTypesController.models.IdeaType;
list: function(req, res, next) {

IdeaType.findAll().success(function(ideaTypes) {
res.send(ideaTypes);
Expand All @@ -13,23 +13,18 @@ var IdeaTypesController = {

count: function(req, res, next) {

var IdeaType = IdeaTypesController.models.IdeaType;

IdeaType.count().success(function(count) {
res.send(count.toString());
});

},

show: function(req, res, next) {

var IdeaType = IdeaTypesController.models.IdeaType;

IdeaType.find(parseInt(req.params.id, 10)).success(function(ideaType) {
res.send(ideaType);
});

}

};

module.exports = IdeaTypesController;
14 changes: 5 additions & 9 deletions webservice/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@

var User = require('../db.js').models.User;

var UsersController = {
module.exports = {

list: function(req, res, next) {

var User = UsersController.models.User;

User.findAll().success(function(users) {
res.send(users);
});

},

count: function(req, res, next) {

var User = UsersController.models.User;

User.count().success(function(count) {
res.send(count.toString());
});

},

show: function(req, res, next) {

var User = UsersController.models.User;

User.find(parseInt(req.params.id, 10)).success(function(user) {
res.send(user);
});

}

};

module.exports = UsersController;

0 comments on commit c2fa914

Please sign in to comment.