Comparing version 0.4.4 to 0.4.5
10
index.js
@@ -42,8 +42,2 @@ // Dependencies | ||
console.log('PATHS') | ||
/* */ controller.get('model').schema.eachPath(function (name, schemaType) { | ||
console.log('"' + name + '"') | ||
console.log(schemaType) | ||
}); | ||
controller.set('basePath', basePath); | ||
@@ -104,4 +98,4 @@ controller.set('basePathWithId', basePathWithId); | ||
if (options.get !== false) controller.get(basePath, configure.conditions, query.getCollection, configure.controller, configure.query, exec.stream, send.stream); | ||
if (options.post !== false) controller.post(basePath, query.postCollection); | ||
if (options.put !== false) controller.put(basePath, query.putCollection, configure.controller, configure.query, exec.exec, send.exec); | ||
if (options.post !== false) controller.post(basePath, query.postCollection, send.exec ); | ||
if (options.put !== false) controller.put(basePath, query.putCollection, configure.controller, configure.query, exec.exec, send.exec); | ||
if (options.del !== false) controller.del(basePath, configure.conditions, query.delCollection, configure.controller, configure.query, exec.exec, send.exec); | ||
@@ -108,0 +102,0 @@ |
@@ -44,5 +44,9 @@ var path = require('path'); | ||
location: function (request, response, next) { | ||
response.set('Location', request.baucis.location); | ||
if (request.baucis.location) response.set('Location', request.baucis.location); | ||
next(); | ||
}, | ||
lastModified: function (request, response, next) { | ||
if (request.baucis.lastModified) response.set('Last-Modified', request.baucis.lastModified); | ||
next(); | ||
} | ||
}; |
@@ -45,5 +45,2 @@ // Private Members | ||
var Model = request.app.get('model'); | ||
var ids = []; | ||
var processedCount = 0; | ||
var wrap; | ||
@@ -55,3 +52,3 @@ // Must be an object or array | ||
// Make it array if it wasn't already | ||
// Make it an array if it wasn't already | ||
if (!Array.isArray(body)) body = [ body ]; | ||
@@ -62,31 +59,9 @@ | ||
wrap = { | ||
open: body.length === 1 ? '' : '[', | ||
close: body.length === 1 ? '' : ']' | ||
}; | ||
// Stream the response JSON array | ||
response.set('Content-Type', 'application/json'); | ||
response.status(201); | ||
response.write(wrap.open); | ||
body.forEach(function (doc) { | ||
Model.create(doc, function (error, savedDoc) { | ||
if (error) return next(error); | ||
processedCount += 1; | ||
response.write(JSON.stringify(savedDoc.toJSON())); | ||
ids.push(savedDoc.id); | ||
// Keep going if there are still more to process | ||
if (processedCount < body.length) return response.write(','); | ||
// Last one was processed | ||
request.baucis.location = request.app.get('basePath') + '?conditions={ _id: { $in: [' + ids.join() + '] } }'; | ||
response.write(wrap.close); | ||
response.send(); | ||
}); | ||
Model.create(body, function (error) { | ||
if (error) return next(error); | ||
var documents = Array.prototype.slice.apply(arguments).slice(1); | ||
request.baucis.documents = documents.length === 1 ? documents[0] : documents; | ||
next(); | ||
}); | ||
@@ -93,0 +68,0 @@ }, |
{ | ||
"name": "baucis", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -1,2 +0,2 @@ | ||
baucis v0.4.4 | ||
baucis v0.4.5 | ||
============= | ||
@@ -3,0 +3,0 @@ |
@@ -15,3 +15,3 @@ var mongoose = require('mongoose'); | ||
var Vegetable = new Schema({ | ||
name: String | ||
name: { type: String, required: true } | ||
}); | ||
@@ -18,0 +18,0 @@ |
@@ -50,2 +50,16 @@ var expect = require('expect.js'); | ||
it('should next validation exceptions', function (done) { | ||
var options = { | ||
url: 'http://localhost:8012/api/v1/vegetables/', | ||
json: {} | ||
}; | ||
request.post(options, function (error, response, body) { | ||
if (error) return done(error); | ||
expect(response).to.have.property('statusCode', 500); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274764
1072