Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* jshint indent: 2 */
- var bcrypt = require('bcrypt');
- var models = require('../models');
- "use strict"
- module.exports = function(sequelize, DataTypes) {
- var User = sequelize.define('user', {
- userID: {
- type: DataTypes.STRING(50),
- allowNull: false,
- primaryKey: true,
- autoIncrement: true
- },
- firstname: {
- type: DataTypes.STRING(50),
- allowNull: true
- },
- surname: {
- type: DataTypes.STRING(50),
- allowNull: true
- },
- phone: {
- type: DataTypes.STRING(50),
- allowNull: false
- },
- email: {
- type: DataTypes.STRING(50),
- allowNull:false
- },
- password: {
- type: DataTypes.STRING(45),
- allowNull: true
- },
- isEmployee: {
- type: DataTypes.TINYINT(4),
- allowNull: true
- }
- }, {
- timestamp: false
- });
- User.hashPassword = function(user, options, callback) {
- bcrypt.hash(user.get('hashedPassword'), 10, function(err, hash) {
- if (err) return callback(err);
- user.update({ hashedPassword: hash}, {fields: ['hashedPassword']}).then(() => {
- console.log("Password updated");
- })
- });
- };
- User.associate = function(models) {
- models.User.hasMany(models.Order, {foreignKey: 'userID'});
- };
- return User;
- };
- User.findAll().then(users => {
- console.log(users)
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement