Commit 0b3b70b0 authored by Kim, Subin's avatar Kim, Subin
Browse files

UserModel 완성 및 RoleModel 미완

parent 9c7f378e
import Sequelize from "sequelize";
const { DataTypes } = Sequelize;
// export const ROLE_NAME = {
// USER = "user",
// MEMBER = "member",
// ADMIN = "admin",
// ROOT = "root",
// }
const RoleModel = (sequelize) => {
const Role = sequelize.define(
"role",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: DataTypes.ENUM({
values: Object.values(ROLE_NAME),
}),
defaultValue: ROLE_NAME.USER,
set(value) {
const lowerCaseName = value.toLowerCase();
this.setDataValue("name", lowerCaseName);
switch (lowerCaseName) {
case ROLE_NAME.USER:
this.priority = 1000;
break;
case ROLE_NAME.MEMBER:
this.priority = 500;
break;
case ROLE_NAME.ADMIN:
this.priority = 50;
break;
case ROLE_NAME.ROOT:
this.priority = 1;
break;
default:
this.priority = 1000;
break;
}
},
},
priority: {
type: DataTypes.INTEGER,
defaultValue: 1000,
},
},
{
timestamps: true,
}
);
return Role;
};
export default RoleModel;
\ No newline at end of file
import bcrypt from "bcryptjs";
import Sequelize from "sequelize";
// import { ROLE_NAME } from "./role.model.js";
const { DataTypes } = Sequelize;
const UserModel = (sequelize) => {
const User = sequelize.define(
"user",
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
userId: {
type: DataTypes.STRING,
},
password: {
type: DataTypes.STRING,
},
nickname: {
type: DataTypes.STRING,
},
birth: {
type: DataTypes.INTEGER,
},
phoneNumber: {
type: DataTypes.INTEGER
},
// role: {
// type: DataTypes.ENUM({
// values: Object.values(ROLE_NAME),
// }),
// }
},
{
timestamps: true,
freezeTableName: true,
tableName: "users"
// defaultScope: {
// attributes: { exclude: ["password"] },
// },
// scopes: {
// withPassword: {
// attributes: { include: ["password"] },
// },
// },
}
);
return User
};
export default UserModel
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment