mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.
MIT License
89 stars 19 forks source link

Add support for Single Embedded Subdocs #31

Closed lykmapipo closed 7 years ago

lykmapipo commented 7 years ago

Fix TypeError: Cannot read property 'type' of null at Object.keys.reduce (lib/mongoose-hidden.js:124:56)

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-10.1%) to 88.281% when pulling 0d13f78998d6fe5454e09661157317362b321364 on lykmapipo:master into a2d2d94c458795385fd4459073c109083b80e07d on mblarsen:master.

rwoody commented 7 years ago

Not sure if it works yet, but I suppressed this error by using:

const MySchemaWithSubdoc = Schema({
  aSubdoc: {type: SomeOtherSchema}
})
mblarsen commented 7 years ago

@rwoody it is not supported at the moment. It does work with nested docs, just not schemas.

mblarsen commented 7 years ago

Also, this PR needs to have at minimum the latest tagged version but preferably master merged in. It also needs to be supported by test cases.

Let me know if you need help with that @lykmapipo

mblarsen commented 7 years ago

@lykmapipo I see that you did include tests; the tests dropped because as you'd left .only on the new tests. I'll try to merge some of this. Thanks for the contribution :)

rwoody commented 7 years ago

@mblarsen Gotcha. Does it work if the Schema also uses this mongoose plugin?

mblarsen commented 7 years ago

@rwoody I do not expect that to work, but you can try and let us know. v1.3 has been published to NPM with the Schema support from this PR.

lykmapipo commented 7 years ago

@mblarsen My bad with only flag on specs(tests). I will be eye open in other contributions.

@rwoody The PR I submitted only support single sub schema. I will try to extend to array of sub schema whenever possible and submit another PR.

@mblarsen Cheer.

rwoody commented 7 years ago

Thanks for the update. I believe it is actually working for me (need to double check though) with something like:

const mySchema = mongoose.Schema({
  tokens: {type: [TokenSchema], hideJSON: true}
})

edit: now that I typed that, I remembering that this issue was for hiding properties within the subschema (so TokenSchema)

mblarsen commented 4 years ago

@rwoody nested schemas are supported now with 1.9

mblarsen commented 4 years ago

@all-contributors add @lykmapipo for bug, maintenance

allcontributors[bot] commented 4 years ago

@mblarsen

I've put up a pull request to add @lykmapipo! :tada: