Skip to content

Instantly share code, notes, and snippets.

@brunoluiz
Created August 24, 2017 03:46
Show Gist options
  • Save brunoluiz/04989863d246ae533fe3b93eb459e64e to your computer and use it in GitHub Desktop.
Save brunoluiz/04989863d246ae533fe3b93eb459e64e to your computer and use it in GitHub Desktop.
// 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