mongoose-hidden
Advanced tools
Comparing version
# Changelog | ||
1.8.1 | ||
- fix bug introduced in 1.7.0 when populating relations using `match` (issue #75) | ||
1.8.0 | ||
@@ -4,0 +8,0 @@ |
@@ -40,7 +40,8 @@ const mpath = require('mpath') | ||
// Map setPath arguments to mpath.set | ||
mpath.set = function(path, value, obj) { | ||
setPath(obj, path, value) | ||
module.exports = { | ||
set: function(path, value, obj) { | ||
setPath(obj, path, value) | ||
}, | ||
get: mpath.get, | ||
unset: mpath.unset, | ||
} | ||
module.exports = mpath |
{ | ||
"name": "mongoose-hidden", | ||
"version": "1.8.0", | ||
"version": "1.8.1", | ||
"author": "Michael Bøcker-Larsen <m19n@pm.me>", | ||
@@ -22,3 +22,3 @@ "description": "Hides certain model properties when invoking toJSON or toObject.", | ||
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js -v && rm -rf ./coverage", | ||
"mocha": "./node_modules/mocha/bin/_mocha", | ||
"mocha": "mocha", | ||
"preversion": "npm run mocha", | ||
@@ -25,0 +25,0 @@ "postversion": "git push && git push --tags" |
@@ -712,6 +712,8 @@ 'use strict' | ||
email: String, | ||
companies: [{ | ||
description: { type: String }, | ||
link: { type: Schema.ObjectId, ref: 'Company' } | ||
}], | ||
companies: [ | ||
{ | ||
description: { type: String }, | ||
link: { type: Schema.ObjectId, ref: 'Company' }, | ||
}, | ||
], | ||
password: { | ||
@@ -726,3 +728,3 @@ type: String, | ||
company.save(function(err, freshCompany) { | ||
user.companies = { description: 'mock-description', link: company._id} | ||
user.companies = { description: 'mock-description', link: company._id } | ||
user.save(function() { | ||
@@ -738,3 +740,3 @@ User.findOne() | ||
should.exist(freshUser.companies[0].description) // failed | ||
should.exist(freshUser.companies[0].link) // failed | ||
should.exist(freshUser.companies[0].link) // failed | ||
@@ -746,4 +748,4 @@ let userJson = freshUser.toJSON() | ||
should.exist(userJson.companies) | ||
should.exist(userJson.companies[0].description) // failed | ||
should.exist(userJson.companies[0].link) // failed | ||
should.exist(userJson.companies[0].description) // failed | ||
should.exist(userJson.companies[0].link) // failed | ||
done() | ||
@@ -950,50 +952,2 @@ }) | ||
// Github issue https://github.com/mblarsen/mongoose-hidden/issues/13 | ||
describe('A documents with non-schema properties set to hidden', function() { | ||
it('should hide the properties', function(done) { | ||
let User = defineModel( | ||
{ | ||
name: String, | ||
email: String, | ||
password: String, | ||
}, | ||
{ hidden: { email: true } } | ||
) | ||
let user = new User(testUser) | ||
user.save(function(err, savedUser) { | ||
User.schema.remove('email') | ||
let User2 = mongoose.model('User', User.schema, undefined, { cache: false }) | ||
User2.findById(savedUser['_id'], function(err2, john) { | ||
let userJson = john.toObject() | ||
let testUserWithoutEmail = { | ||
name: testUser.name, | ||
password: testUser.password, | ||
} | ||
userJson.should.deepEqual(testUserWithoutEmail) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
// Github issue https://github.com/mblarsen/mongoose-hidden/issues/12 | ||
describe('A model with nested documents', function() { | ||
it('should return only the visible parts', function(done) { | ||
let User = defineModel({ | ||
name: String, | ||
email: { | ||
prefix: { type: String }, | ||
suffix: { type: String, hide: true }, | ||
}, | ||
password: String, | ||
}) | ||
let user = new User(testUser3) | ||
let userJson = user.toObject() | ||
let testUser3WithoutEmailSuffix = Object.assign({}, testUser3) | ||
delete testUser3WithoutEmailSuffix.email.suffix | ||
userJson.should.deepEqual(testUser3WithoutEmailSuffix) | ||
done() | ||
}) | ||
}) | ||
describe('Setting a path on an object', function() { | ||
@@ -1000,0 +954,0 @@ it('should set plain property', function() { |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
66330
6.05%19
5.56%1704
7.3%0
-100%