ee-soa-service
Advanced tools
Comparing version 0.2.47 to 0.2.48
@@ -159,2 +159,4 @@ !function() { | ||
* nothig | ||
* @param {string} [token=undefined] token optional accessToken | ||
* | ||
* @returns {promise|undefined} a promise if no callback or response | ||
@@ -161,0 +163,0 @@ * was passed or nothing |
@@ -396,3 +396,3 @@ | ||
if(this._controllerLoadCount <= 0) { | ||
log.info('['+this.name+'] controllers loaded'); | ||
log.info('The service «'+this.name+'» has finished loading its '+this._conf.controllersToLoad.length+' controllers ...'); | ||
this._loaded = true; | ||
@@ -399,0 +399,0 @@ this.emit('load'); |
@@ -0,63 +1,72 @@ | ||
!function() { | ||
'use strict'; | ||
!function() { | ||
'use strict'; | ||
var Class = require('ee-class') | ||
, log = require('ee-log') | ||
, DefaultController = require('./DefaultController') | ||
, DefaultORMController = require('./DefaultORMController') | ||
, DefaultService = require('./DefaultService') | ||
, EventEmitter = require('ee-event-emitter') | ||
, argv = require('ee-argv') | ||
, debug = argv.has('dev-service'); | ||
var Class = require('ee-class') | ||
, log = require('ee-log') | ||
, DefaultController = require('./DefaultController') | ||
, DefaultORMController = require('./DefaultORMController') | ||
, DefaultService = require('./DefaultService') | ||
, EventEmitter = require('ee-event-emitter') | ||
, argv = require('ee-argv') | ||
, debug = argv.has('dev-service'); | ||
module.exports = new Class({ | ||
inherits: DefaultService | ||
, init: function init(options, dirname) { | ||
this.options = options || {}; | ||
module.exports = new Class({ | ||
inherits: DefaultService | ||
init.super.call(this, options, dirname); | ||
, init: function init(options, dirname) { | ||
this.options = options || {}; | ||
// set the servicename as controller option | ||
if (!this.options.controllerOption) this.options.controllerOption = {}; | ||
this.options.controllerOptions.serviceName = this.name; | ||
} | ||
, _initDefaultController: function(loaded) { | ||
if(Object.hasOwnProperty.call(this.options, 'controllerOptions') && Object.hasOwnProperty.call(this.options.controllerOptions, 'orm')) { | ||
this._conf.tablesToLoad.forEach(function(table, index) { | ||
try { | ||
this.options.controllerOptions.table = table; | ||
var controller = new DefaultORMController(this.options.controllerOptions); | ||
} catch (err) { | ||
throw new Error('['+this.name+'] Could not load DefaultController-File for table "' + table + '"'); | ||
} | ||
init.super.call(this, options, dirname); | ||
// set the servicename as controller option | ||
if (!this.options.controllerOption) this.options.controllerOption = {}; | ||
this.options.controllerOptions.serviceName = this.name; | ||
} | ||
// make sure each controller rknows its name | ||
if (!controller.name) controller.name = table; | ||
if (!controller.serviceName) controller.serviceName = this.name; | ||
controller.on('load', function(err) { | ||
if(err) throw err; | ||
if(debug) log('['+this.name+'] DefaultController "' + table + '" loaded...'); | ||
this._controllerCollection[table] = controller; | ||
loaded(); | ||
}.bind(this)); | ||
, _initDefaultController: function(loaded) { | ||
if(Object.hasOwnProperty.call(this.options, 'controllerOptions') && Object.hasOwnProperty.call(this.options.controllerOptions, 'orm')) { | ||
this._conf.tablesToLoad.forEach(function(table, index) { | ||
try { | ||
this.options.controllerOptions.table = table; | ||
var controller = new DefaultORMController(this.options.controllerOptions); | ||
} catch (err) { | ||
throw new Error('['+this.name+'] Could not load DefaultController-File for table "' + table + '"'); | ||
} | ||
controller.on('request', this._handleRequest.bind(this)); | ||
// make sure each controller rknows its name | ||
if (!controller.name) controller.name = table; | ||
if (!controller.serviceName) controller.serviceName = this.name; | ||
controller.on('load', function(err) { | ||
if(err) throw err; | ||
if(debug) log('['+this.name+'] DefaultController "' + table + '" loaded...'); | ||
this._controllerCollection[table] = controller; | ||
loaded(); | ||
}.bind(this)); | ||
} | ||
controller.on('request', this._handleRequest.bind(this)); | ||
}.bind(this)); | ||
} | ||
} | ||
, _listAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].list) | ||
return callback(new Error("list action not implemented on controller")); | ||
, _listAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].list) callback(new Error('The list action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].list(req, function(err, result, status, headers) { | ||
@@ -67,7 +76,10 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _listOneAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].listOne) | ||
return callback(new Error("listOne action not implemented on controller")); | ||
, _listOneAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].listOne) callback(new Error('The listOne action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].listOne(req, function(err, result, status, headers) { | ||
@@ -77,7 +89,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _createAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].create) | ||
return callback(new Error("create action not implemented on controller")); | ||
, _createAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].create) callback(new Error('The create action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].create(req, function(err, result, status, headers) { | ||
@@ -87,7 +103,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _updateAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].update) | ||
return callback(new Error("update action not implemented on controller")); | ||
, _updateAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].update) callback(new Error('The list update is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].update(req, function(err, result, status, headers) { | ||
@@ -97,7 +117,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _createOrUpdateAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].createOrUpdate) | ||
return callback(new Error("createOrUpdate action not implemented on controller")); | ||
, _createOrUpdateAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].createOrUpdate) callback(new Error('The createOrUpdate action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].createOrUpdate(req, function(err, result, status, headers) { | ||
@@ -107,7 +131,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _createRelationAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].createRelation) | ||
return callback(new Error("createRelation action not implemented on controller")); | ||
, _createRelationAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].createRelation) callback(new Error('The createRelation action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].createRelation(req, function(err, result, status, headers) { | ||
@@ -117,7 +145,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _deleteAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].delete) | ||
return callback(new Error("delete action not implemented on controller")); | ||
, _deleteAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].delete) callback(new Error('The delete action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].delete(req, function(err, result, status, headers) { | ||
@@ -127,7 +159,11 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
} | ||
, _describeAction: function(collection, req, callback) { | ||
if(!this._controllerCollection[collection].describe) | ||
return callback(new Error("describe action not implemented on controller")); | ||
, _describeAction: function(collection, req, callback) { | ||
if (!this._controllerCollection[collection].describe) callback(new Error('The describe action is not implemented on the «'+this.name+'.'+collection+'» controller!')); | ||
else { | ||
this._controllerCollection[collection].describe(req, function(err, result, status, headers) { | ||
@@ -137,5 +173,4 @@ this._handleResponse(err, result, req, callback, status, headers); | ||
} | ||
}); | ||
}(); | ||
} | ||
}); | ||
}(); |
@@ -5,3 +5,3 @@ { | ||
, "keywords" : ["ee", "soa", "service"] | ||
, "version" : "0.2.47" | ||
, "version" : "0.2.48" | ||
, "author": { | ||
@@ -8,0 +8,0 @@ "name" : "Tobias Kneubuehler" |
90779
1526