hapi-forest
Advanced tools
Comparing version 0.7.1 to 0.7.2
@@ -7,3 +7,3 @@ 'use strict'; | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-example', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-example'); | ||
@@ -10,0 +10,0 @@ const server = new hapi.server({ port: 8080 }); |
@@ -14,3 +14,3 @@ 'use strict'; | ||
if (options.preQuery) options.preQuery(query); // query extension point | ||
let item = await Model.findOneAndUpdate(query, req.payload, { new: true }).lean().exec(); | ||
let item = await Model.findOneAndUpdate(query, req.payload, { new: true }).lean().catch(hu.handleError); | ||
if (item === null) throw boom.notFound(`${Model.modelName} not found`); | ||
@@ -17,0 +17,0 @@ if (options.transformResponse) item = options.transformResponse(item, req); |
@@ -14,6 +14,6 @@ 'use strict'; | ||
const query = Model.updateOne(condition, req.payload, { | ||
overwrite: options.overwrite, | ||
upsert: options.upsert, | ||
}).lean(); | ||
const { overwrite, upsert } = options; | ||
const query = overwrite | ||
? Model.replaceOne(condition, req.payload, { upsert }) | ||
: Model.updateOne(condition, req.payload, { upsert }); | ||
@@ -20,0 +20,0 @@ if (options.preQuery) options.preQuery(query); // query extension point |
{ | ||
"name": "hapi-forest", | ||
"version": "0.7.1", | ||
"version": "0.7.2", | ||
"description": "A hapi plugin to generate routes based on mongoose models", | ||
@@ -57,3 +57,3 @@ "main": "forest.js", | ||
"make-promises-safe": "^1.1.0", | ||
"mongoose": "^4.7.2", | ||
"mongoose": "^5.4.8", | ||
"nodemon": "^1.13.3", | ||
@@ -60,0 +60,0 @@ "nyc": "^11.3.0", |
@@ -5,3 +5,3 @@ const test = require('ava'); | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-test', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-test'); | ||
const createServer = require('./helpers/createServer.js'); | ||
@@ -8,0 +8,0 @@ const CatModel = require('./fixtures/test-cat-model'); |
@@ -5,3 +5,3 @@ const test = require('ava'); | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-test', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-test'); | ||
const createServer = require('./helpers/createServer.js'); | ||
@@ -8,0 +8,0 @@ const CatModel = require('./fixtures/test-cat-model'); |
@@ -5,3 +5,3 @@ const test = require('ava'); | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-test', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-test'); | ||
const createServer = require('./helpers/createServer.js'); | ||
@@ -8,0 +8,0 @@ const CatModel = require('./fixtures/test-cat-model'); |
@@ -5,3 +5,3 @@ const test = require('ava'); | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-test', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-test'); | ||
const createServer = require('./helpers/createServer.js'); | ||
@@ -8,0 +8,0 @@ const CatModel = require('./fixtures/test-cat-model'); |
@@ -5,3 +5,3 @@ const test = require('ava'); | ||
mongoose.Promise = global.Promise; | ||
mongoose.connect('mongodb://localhost/forest-test', { useMongoClient: true }); | ||
mongoose.connect('mongodb://localhost/forest-test'); | ||
const createServer = require('./helpers/createServer.js'); | ||
@@ -35,2 +35,4 @@ const CatModel = require('./fixtures/test-cat-model'); | ||
t.is(res.statusCode, 201, 'Status code is 201'); | ||
t.is(res.result.name, 'PutCat1', 'Correct name saved'); | ||
t.is(res.result.fromTest, 'put', 'Correct data saved'); | ||
@@ -58,4 +60,6 @@ const dbEntry = await CatModel.findOne({ name: 'PutCat1' }).lean(); | ||
const res = await put('PutCatTimestamp', { fromTest: 'put' }); | ||
const res = await put('PutCatTimestamp', { fromTest: 'put', meta: { age: 2 } }); | ||
t.is(res.statusCode, 201, 'Status code is 201'); | ||
t.is(res.result.name, 'PutCatTimestamp', 'response has correct name'); | ||
t.is(res.result.meta.age, 2, 'response has correct meta'); | ||
@@ -65,2 +69,3 @@ const dbEntry = await CatModelTimestamps.findOne({ name: 'PutCatTimestamp' }).lean(); | ||
t.is(dbEntry.name, 'PutCatTimestamp', 'entry has right name'); | ||
t.is(dbEntry.meta.age, 2, 'entry has right meta'); | ||
}); | ||
@@ -100,2 +105,3 @@ | ||
t.is(res2.statusCode, 200, 'Status code is 200'); | ||
t.is(res2.result.meta.age, 1, 'entry the updated age'); | ||
@@ -102,0 +108,0 @@ const updatedDbEntry = await CatModel.findOne({ name: 'PutCat2' }).lean(); |
Sorry, the diff of this file is not supported yet
42985
1036