Dashride / mongoose-stripe-customers

A configurable mongoose.js plugin that creates a Stripe customer when a new document is created, then stores the Stripe customer ID to that document.
Apache License 2.0
8 stars 2 forks source link

Add embedded document name support. ("name.first", "name.last") #2

Closed AustinHunt closed 8 years ago

AustinHunt commented 8 years ago

Your module works great as long as you define your names in the base of the schema like this: {first_name: String, last_name:String}

The second you want your schema to be like this: {name : {first : String, last:String}}

You run into problems.

I wrote a function that fixes this. Either include it or add me to the repo and I'll make the changes.

var getProperty = function(key, doc) { var item = doc; var keys = key.split('.'); var iterations = keys.length - 1; for (var i = 0; i < iterations; i++) { item = item[keys.shift()]; }; return item[keys[0]];// Returns a 'pointer' to the correct property. }

jrthib commented 8 years ago

@NomadGraphix the plugin has been updated to support what you were requesting.

Also, in the future, feel free to fork the repo and submit a pull request, contributions are welcome :)