Created
August 24, 2017 03:46
-
-
Save brunoluiz/04989863d246ae533fe3b93eb459e64e 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
// rating.js | |
const mongoose = require('mongoose') | |
const joigoose = require('joigoose')(mongoose) | |
// Require the 'ratings' schema | |
const schema = require('./rating-schema') | |
// Convert joi to mongoose schema | |
const mongooseSchema = joigoose.convert(schema); | |
// Modify some fields with database specific instructions | |
mongooseSchema.email.unique = true | |
// Add fields which don't make sense on the schema validator | |
mongooseSchema.updatedAt = { type: Date, default: Date.now } | |
mongooseSchema.createdAt = { type: Date, default: Date.now } | |
// Define mongoose model | |
const Ratings = mongoose.model('Ratings', mongooseSchema) | |
module.exports = Ratings |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment