Skip to content
This repository has been archived by the owner on Jul 12, 2018. It is now read-only.

Commit

Permalink
- detecting readCollection service-method works now
Browse files Browse the repository at this point in the history
- closes #195
  • Loading branch information
meaku committed Jul 23, 2013
1 parent 004c77c commit 5086af1
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/server/request/middleware/runService.js
Expand Up @@ -60,7 +60,7 @@ function runService(req, res, next) {
//the service registry only has server-services on the server-side!
service = services.getService(path);

if (service[method] === undefined) {
if (value(service[method]).notTypeOf(Function)) {
log.debug("Unsupported Method: " + method);
onServiceCallFailed();
}
Expand All @@ -69,7 +69,6 @@ function runService(req, res, next) {
case 'create':
//model = ModelClass , data = pure request data
if (value(model).instanceOf(Model)) {

model.save(false, function (err, response) {
onServiceCallback(response);
});
Expand All @@ -79,19 +78,11 @@ function runService(req, res, next) {
}
break;
case 'read':
//if no id is set, we have a collection request
//READ COLLECTION
if (id === undefined || id === null) {
if (value(service.readCollection).notTypeOf(Function)) {
onServiceCallFailed();
break;
}
//data = pure request data
handleServiceCall(service.readCollection.bind(service), ids, data, onServiceCallback);
break;
}
handleServiceCall(service.read.bind(service), ids, onServiceCallback);
break;
case 'readCollection' :
handleServiceCall(service.readCollection.bind(service), ids, data, onServiceCallback);
break;
case 'update':
if (value(model).instanceOf(Model)) {
model.save(function (err, response) {
Expand Down Expand Up @@ -157,6 +148,12 @@ function runService(req, res, next) {
next(null);
}

//detect readCollection requests
//read request without id = readCollection
if (method === "read" && (id === undefined || id === null)) {
method = "readCollection";
}

//attach the data to the model if model = modelInstance
if (value(model).instanceOf(Model)) {
model.setIds(ids);
Expand Down

0 comments on commit 5086af1

Please sign in to comment.