@@ -22,15 +22,15 @@ _.str = require('underscore.string');
22
22
function ResourceController ( modelName , opts ) {
23
23
var db = app . locals . db ;
24
24
this . db = db ;
25
- this . options = opts ,
25
+ this . options = opts ;
26
26
this . modelName = modelName ; // user
27
27
this . modelNamePlural = inflection . pluralize ( this . modelName ) ; // users
28
28
this . ModelClass = db [ _ . str . capitalize ( this . modelName ) ] ; // User
29
29
this . modelGetter = 'get' + _ . str . capitalize ( this . modelName ) ; // getUser
30
30
this . modelGetterPlural = inflection . pluralize ( this . modelGetter ) ; // getUsers
31
31
this . modelSetter = 'set' + _ . str . capitalize ( this . modelName ) ;
32
32
this . modelSetterPlural = inflection . pluralize ( this . modelSetter ) ;
33
- this . log = new app . locals . Logger ( app . locals . conf )
33
+ this . log = new app . locals . Logger ( app . locals . conf ) ;
34
34
this . dialect = 'postgres' ;
35
35
36
36
var scopeCheck = function ( req , res , next ) {
@@ -47,7 +47,7 @@ function ResourceController(modelName, opts) {
47
47
if ( this . options . before ) {
48
48
if ( this . options . before && this . options . before . all ) { // options.before.all exists
49
49
if ( _ . isArray ( this . options . before . all ) ) { // options.before.all is an Array, prepend it
50
- this . options . before . all . unshift ( scopeCheck )
50
+ this . options . before . all . unshift ( scopeCheck ) ;
51
51
}
52
52
else { // options.before.all is an Object, convert to an Array and prepend.
53
53
this . options . before . all = [ scopeCheck , this . options . before . all ] ;
@@ -64,7 +64,7 @@ function ResourceController(modelName, opts) {
64
64
65
65
// maintains 'this' context throughout the class
66
66
_ . bindAll ( this ) ;
67
- } ;
67
+ }
68
68
69
69
ResourceController . prototype . index = function ( req , res ) {
70
70
var _this = this ,
@@ -101,7 +101,7 @@ ResourceController.prototype.index = function(req, res) {
101
101
. error ( function ( err ) { _this . sendErr ( res , 'index' , err ) ; } )
102
102
. success ( function ( result , created ) {
103
103
if ( result . length === 1 )
104
- return res . send ( result [ 0 ] )
104
+ return res . send ( result [ 0 ] ) ;
105
105
res . send ( result ) ;
106
106
} ) ;
107
107
}
@@ -146,7 +146,7 @@ ResourceController.prototype.new = function(req, res) {
146
146
ResourceController . prototype . create = function ( req , res ) {
147
147
var action = 'create' ,
148
148
params = req . body ,
149
- modelParam = params [ this . modelName ] // { theModelName : { attr : value }}
149
+ modelParam = params [ this . modelName ] ; // { theModelName : { attr : value }}
150
150
_this = this ;
151
151
152
152
if ( _ . isEmpty ( modelParam ) ) return _this . sendErr ( res , action , 'no ' + this . modelName + ' parameter supplied' ) ;
@@ -222,15 +222,15 @@ ResourceController.prototype.update = function(req, res) {
222
222
var setKeys = _ . keys ( params . update ) ; // ['key', 'key2', 'key3']
223
223
var setString = '' ;
224
224
var setArray = _ . map ( setKeys , function ( key ) { // [ '"name"=\'Bob\'','"age=16"', '"desc"=\'A user\'' ]
225
- var value = params . update [ key ]
225
+ var value = params . update [ key ] ;
226
226
value = _ . isNumber ( params . update [ key ] ) ? value : SqlString . escape ( value , null , null , _this . dialect ) ;
227
227
return "\"" + key + "\"=" + value ;
228
228
} ) ;
229
229
230
230
if ( setArray . length > 1 ) {
231
231
// "name"='Bob',"age=16"
232
232
setString += setArray . shift ( ) ;
233
- _ . each ( setArray , function ( setter ) { setString += ( ',' + setter ) ; } )
233
+ _ . each ( setArray , function ( setter ) { setString += ( ',' + setter ) ; } ) ;
234
234
235
235
} else {
236
236
// "name"='Bob'
@@ -239,10 +239,10 @@ ResourceController.prototype.update = function(req, res) {
239
239
240
240
241
241
// :/ this gets us the relational piece of the update query
242
- var query = 'UPDATE ' + this . modelNamePlural + ' SET ' + setString
243
- + ' WHERE id IN (SELECT "' + this . modelName + 'Id"'
244
- + ' FROM ' + this . modelNamePlural + inflection . pluralize ( req . scope . daoFactory . name )
245
- + ' WHERE "' + req . scope . daoFactory . name + 'Id" = ' + req . scope . id + ')' ;
242
+ var query = 'UPDATE ' + this . modelNamePlural + ' SET ' + setString +
243
+ ' WHERE id IN (SELECT "' + this . modelName + 'Id"' +
244
+ ' FROM ' + this . modelNamePlural + inflection . pluralize ( req . scope . daoFactory . name ) +
245
+ ' WHERE "' + req . scope . daoFactory . name + 'Id" = ' + req . scope . id + ')' ;
246
246
247
247
248
248
if ( _ . isEmpty ( params . where ) ) {
@@ -263,7 +263,7 @@ ResourceController.prototype.update = function(req, res) {
263
263
query += whereQuery ;
264
264
}
265
265
_this . db . sequelize . query ( query )
266
- . error ( function ( err ) { _this . sendErr ( res , action , err ) } )
266
+ . error ( function ( err ) { _this . sendErr ( res , action , err ) ; } )
267
267
. success ( function ( ) {
268
268
res . send ( { status : 'success' } ) ;
269
269
} ) ;
@@ -337,16 +337,17 @@ ResourceController.prototype.query = function(req, res) {
337
337
ResourceController . prototype . describe = function ( req , res ) {
338
338
var data = this . db . describe ( this . ModelClass ) ;
339
339
340
- if ( data == null )
340
+ if ( data === null ) {
341
341
data = { error : 'This model does not exist' } ;
342
+ }
342
343
343
344
res . setHeader ( 'Sequelize-Admin' , JSON . stringify ( data ) ) ;
344
345
res . end ( ) ;
345
346
} ;
346
347
347
348
ResourceController . prototype . getLogger = function ( ) {
348
349
return this . log ;
349
- }
350
+ } ;
350
351
351
352
function isInt ( arg ) {
352
353
var intRegex = / ^ \d + $ / ;
@@ -362,6 +363,6 @@ ResourceController.prototype.sendErr = function (res, action, msg) {
362
363
363
364
this . log . error ( err ) ;
364
365
res . send ( err ) ;
365
- }
366
+ } ;
366
367
367
368
exports = module . exports = ResourceController ;
0 commit comments