Advertisement
Guest User

Untitled

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