user.model.js 715 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
import bcrypt from "bcryptjs";
import Sequelize from "sequelize";

const { DataTypes } = Sequelize;

const UserModel = (sequelize) => {
  const User = sequelize.define(
    "user",
    {
Choi Ga Young's avatar
Choi Ga Young committed
10
      userID: {
11
12
        type: DataTypes.STRING
      },
Choi Ga Young's avatar
Choi Ga Young committed
13
14
15
16
17
18
19
20
21
      userName: {
        type: DataTypes.STRING
      },
      password: {
        type: DataTypes.STRING
      },
      studNum: {
        type: DataTypes.STRING
      }
22
    }
Choi Ga Young's avatar
Choi Ga Young committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  );

  User.beforeSave(async (user) => {
    // if (!user.changed("password")) {
    //   return;
    // }
    if (user.password) {
      const hashedPassword = await bcrypt.hash(user.password, 10);
      user.password = hashedPassword;
    }
  });
  return User
};


export default UserModel;