Skip to content

Instantly share code, notes, and snippets.

@highfeed
Created December 18, 2020 14:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save highfeed/c0a5eafb41584e08fbf599d86ab40cb5 to your computer and use it in GitHub Desktop.
Save highfeed/c0a5eafb41584e08fbf599d86ab40cb5 to your computer and use it in GitHub Desktop.
Dice model
const mongoose = require('mongoose')
const {Schema} = mongoose
const Dice = new Schema({
type: Number,
transaction_id: mongoose.ObjectId,
owner_id: Number,
prize: Number,
parity: String,
value: Number,
is_win: Boolean,
rate: Number,
coeff: Number,
created_at: Date,
}, {versionKey: false})
Dice.pre('save', function (next) {
if (this.created_at === undefined) {
this.created_at = new Date()
}
return next()
})
module.exports = mongoose.model('Dice', Dice)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment