You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const sequelize = require("sequelize");
|
|
|
|
const db = require("../Config/db");
|
|
|
|
const bcrypt = require("bcryptjs")
|
|
|
|
const jwt = require("jsonwebtoken")
|
|
|
|
|
|
|
|
const UserModel = db.define(
|
|
|
|
"TDUSERS",
|
|
|
|
{
|
|
|
|
USER_ID: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
primaryKey: true,
|
|
|
|
},
|
|
|
|
USER_CODE: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_NAME: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_DESC: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIRST_NAME: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
LAST_NAME: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
ADDRESS: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
PHONE: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
EMAIL: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
MAP: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_PASS: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_STATUS: {
|
|
|
|
type: sequelize.CHAR,
|
|
|
|
},
|
|
|
|
USER_TYPE: {
|
|
|
|
type: sequelize.CHAR,
|
|
|
|
},
|
|
|
|
USER_LOG: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_CPAS: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
},
|
|
|
|
APPROVED: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
},
|
|
|
|
APPROVED_BY: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
EMP_CODE: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_PERIOD: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
},
|
|
|
|
FIELD_0: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_1: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_2: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_3: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_4: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_5: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_6: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_7: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
FIELD_8: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
},
|
|
|
|
FIELD_9: {
|
|
|
|
type: sequelize.DATE,
|
|
|
|
},
|
|
|
|
USER_CREATED: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
USER_CREDATE: {
|
|
|
|
type: sequelize.DATE,
|
|
|
|
},
|
|
|
|
USER_UPDT: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
DATE_UPDT: {
|
|
|
|
type: sequelize.DATE,
|
|
|
|
},
|
|
|
|
DEPARTMENT_ID: {
|
|
|
|
type: sequelize.INTEGER,
|
|
|
|
},
|
|
|
|
ROLE_TYPE: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
DEVICE_TOKEN: {
|
|
|
|
type: sequelize.STRING,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
timestamps: false,
|
|
|
|
freezeTableName: true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
UserModel.removeAttribute("id")
|
|
|
|
|
|
|
|
//hashPassword
|
|
|
|
UserModel.encryptPass = function (pass) {
|
|
|
|
return bcrypt.hashSync(pass, bcrypt.genSaltSync(10), null)
|
|
|
|
};
|
|
|
|
|
|
|
|
UserModel.prototype.getSignedJwtToken = function (dbCode, appCode, custCode) {
|
|
|
|
return jwt.sign({ id: this.USER_ID, dbCode: dbCode, appCode: appCode, custCode: custCode }, process.env.JWT_SECRET, {
|
|
|
|
expiresIn: process.env.JWT_EXPIRE,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
//comparePassword
|
|
|
|
UserModel.prototype.matchPassword = function (enteredPassword) {
|
|
|
|
return bcrypt.compareSync(enteredPassword, this.USER_PASS)
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = UserModel
|