Created
December 18, 2020 14:34
-
-
Save highfeed/c0a5eafb41584e08fbf599d86ab40cb5 to your computer and use it in GitHub Desktop.
Dice model
This file contains hidden or 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 | |
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