Guest User

Untitled

a guest
Jan 29th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var mongoose = require('mongoose')
  2. var Schema = mongoose.Schema
  3. var bcrypt = require('bcrypt-nodejs')
  4.  
  5. var TransactionSchema = new Schema({
  6.     time: {
  7.         type: String
  8.     },
  9.     date : {
  10.         type: String
  11.     },
  12.     transactionType : {
  13.         type: String
  14.     },
  15.     email : {
  16.         type: String
  17.     },
  18.     amount: {
  19.         type: String
  20.     },
  21.     txHash:{
  22.         type: String
  23.     }
  24. })
  25.  
  26. var UserSchema = new Schema({
  27.     username: {
  28.         type: String
  29.     },
  30.     email: {
  31.         type: String,
  32.     },
  33.     password: {
  34.         type: String
  35.     },
  36.     ethAddress: {
  37.         type: String
  38.     },
  39.     privateKey: {
  40.         type: String
  41.     },
  42.     transactions: TransactionSchema
  43. })
  44.  
  45. UserSchema.pre('save', function(next){
  46.     var user = this;
  47.     bcrypt.hash(user.password, null, null, function(err,hash){
  48.         if(err) return next(err)
  49.         user.password = hash
  50.         next()
  51.     })
  52. })
  53.  
  54. module.exports = mongoose.model('User', UserSchema)
Add Comment
Please, Sign In to add comment