restful-goose
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -31,2 +31,5 @@ var _ = require('lodash'); | ||
var toLinkObject = function(modelName, id) { | ||
if (id.toString) { | ||
id = id.toString(); | ||
} | ||
return { type: toResourceType(modelName), id: id, link: '/' + toResourceType(modelName) + '/' + id }; | ||
@@ -136,3 +139,3 @@ }; | ||
if (Object.keys(relationships).length) { | ||
deserialized.relationships = relationships; | ||
Object.assign(deserialized, o.relationships); | ||
} | ||
@@ -139,0 +142,0 @@ |
@@ -90,3 +90,5 @@ var helpers = require('./helpers'); | ||
debug('findOne() invoked'); | ||
if (!mongoose.Types.ObjectId.isValid(req.params.item_id)) { | ||
debug(`NotFound pushed to errors stack because ${req.params.item_id} is not a valid MongoDB ID`); | ||
res.errors.push(res.rg.ERR.NOT_FOUND()); | ||
@@ -97,3 +99,3 @@ return next(); | ||
if (err) { res.errors.push(err); } | ||
if (!item) { res.errors.push(res.rg.ERR.NOT_FOUND()); } | ||
if (!item) { res.errors.push(res.rg.ERR.NOT_FOUND()); debug('NotFound pushed to errors stack'); } | ||
if (err || !item) { | ||
@@ -117,3 +119,3 @@ return next(); | ||
ParentModel.findById(req.params.parent_item_id, function(err, parentItem) { | ||
var reference = _.find(parentItem.constructor.schema.paths, function(path) { | ||
var reference = _.find(parentItem.constructor.schema.paths, function(path) { | ||
return path.options && path.options.ref === res.rg.Model.modelName; | ||
@@ -120,0 +122,0 @@ }); |
{ | ||
"name": "restful-goose", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A new improved version of your favorite API framework for mongoose/MongoDB", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -43,3 +43,3 @@ var faker = require('faker'); | ||
case 'ObjectID': | ||
if (path.options.ref) { | ||
if (path.options.ref && docs[path.options.ref] && docs[path.options.ref].length) { | ||
o[pathName] = _.sample(docs[path.options.ref])._id; | ||
@@ -82,2 +82,4 @@ } | ||
return function(mongoose, itemCount, done) { | ||
var models; | ||
if (typeof itemCount === 'function') { | ||
@@ -88,5 +90,7 @@ done = itemCount; | ||
} | ||
async.eachSeries(mongoose.models, generateData, done); | ||
models = _.sortBy(mongoose.models, 'modelName').reverse(); | ||
async.eachSeries(models, generateData, done); | ||
}; | ||
}()); |
@@ -8,2 +8,4 @@ var mongoose = require('mongoose'); | ||
name: { type: mongoose.Schema.Types.String, index: true }, | ||
isCool: { type: mongoose.Schema.Types.Boolean, default: true }, | ||
rank: { type: mongoose.Schema.Types.Number, default: 14 }, | ||
subs: { type: [mongoose.Schema.Types.ObjectId], ref: 'SubTest' } | ||
@@ -10,0 +12,0 @@ }, { timestamps: true }); |
@@ -15,6 +15,4 @@ var mongoose = require('mongoose'); | ||
if (this.isNew || this.isModified('parent')) { | ||
RequestTest.findOneAndUpdate({ subs: this._id }, { $pull: { subs: this._id }}, function() { | ||
RequestTest.findOneAndUpdate({ _id: _this.parent }, { $push: { subs: _this._id }}, next); | ||
}); | ||
if (this.parent && this.isNew || this.isModified('parent')) { | ||
RequestTest.findOneAndUpdate({ _id: _this.parent }, { $push: { subs: _this._id }}, next); | ||
} else { | ||
@@ -21,0 +19,0 @@ next(); |
@@ -29,2 +29,8 @@ /* globals describe, before, after, it */ | ||
}); | ||
after(function(done) { | ||
connection.db.dropDatabase(function() { | ||
connection.close(done); | ||
}); | ||
}); | ||
@@ -35,3 +41,3 @@ describe('GET methods', function() { | ||
before(function(done) { | ||
connection.model('RequestTest').findOne({ subs: { $size: 1 }}, {}, function(err, result) { | ||
connection.model('RequestTest').findOne({ subs: { $exists: true }}, {}, function(err, result) { | ||
sampleItem = result; | ||
@@ -62,3 +68,3 @@ done(); | ||
expect(res.body.data[0].attributes).to.not.have.property('subs'); | ||
expect(res.body.data[0].attributes).to.have.all.keys(['name', 'created-at' ,'updated-at']); | ||
expect(res.body.data[0].attributes).to.have.all.keys(['name', 'rank', 'is-cool', 'created-at' ,'updated-at']); | ||
done(); | ||
@@ -78,3 +84,3 @@ }); | ||
expect(res.body.data.type).to.equal('request-tests'); | ||
expect(res.body.data.attributes).to.have.all.keys(['name', 'created-at', 'updated-at']); | ||
expect(res.body.data.attributes).to.have.all.keys(['name', 'is-cool', 'rank', 'created-at', 'updated-at']); | ||
done(); | ||
@@ -81,0 +87,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1133128
56
1956
0