Created
February 17, 2019 16:27
-
-
Save funador/98e524778dd92b1141255c8aadb94e1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose') | |
const Schema = mongoose.Schema | |
const { providers } = require('../config') | |
// | |
const providerFields = providers.reduce((obj, provider) => { | |
obj[provider] = { | |
name: { | |
type: String | |
}, | |
photo: { | |
type: String | |
} | |
} | |
return obj | |
}, {}) | |
// | |
const fields = { | |
email: { | |
type: String, | |
unique: true | |
}, | |
...providerFields | |
} | |
// One nice, clean line to create the Schema. | |
const userSchema = new Schema(fields) | |
module.exports = mongoose.model('User', userSchema) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment