Advertisement
Guest User

Untitled

a guest
Mar 8th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. /* jshint indent: 2 */
  2. var bcrypt = require('bcrypt');
  3. var models = require('../models');
  4. "use strict"
  5.  
  6. module.exports = function(sequelize, DataTypes) {
  7. var User = sequelize.define('user', {
  8. userID: {
  9. type: DataTypes.STRING(50),
  10. allowNull: false,
  11. primaryKey: true,
  12. autoIncrement: true
  13. },
  14. firstname: {
  15. type: DataTypes.STRING(50),
  16. allowNull: true
  17. },
  18. surname: {
  19. type: DataTypes.STRING(50),
  20. allowNull: true
  21. },
  22. phone: {
  23. type: DataTypes.STRING(50),
  24. allowNull: false
  25. },
  26. email: {
  27. type: DataTypes.STRING(50),
  28. allowNull:false
  29. },
  30. password: {
  31. type: DataTypes.STRING(45),
  32. allowNull: true
  33. },
  34. isEmployee: {
  35. type: DataTypes.TINYINT(4),
  36. allowNull: true
  37. }
  38. }, {
  39. timestamp: false
  40. });
  41.  
  42. User.hashPassword = function(user, options, callback) {
  43. bcrypt.hash(user.get('hashedPassword'), 10, function(err, hash) {
  44. if (err) return callback(err);
  45. user.update({ hashedPassword: hash}, {fields: ['hashedPassword']}).then(() => {
  46. console.log("Password updated");
  47. })
  48. });
  49. };
  50.  
  51. User.associate = function(models) {
  52. models.User.hasMany(models.Order, {foreignKey: 'userID'});
  53. };
  54.  
  55. return User;
  56.  
  57. };
  58.  
  59.  
  60. User.findAll().then(users => {
  61. console.log(users)
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement