const { DataTypes } = require('sequelize'); const connect = require('./connect'); const { isProd } = require('../../config'); /* type: DataTypes.STRING, allowNull: false, defaultValue:'', comment: '名', */ function formatTime(m) { // m.auth && (m.auth = JSON.parse(m.auth)); } const model = connect.define( __filename.slice(__dirname.length + 1).replace('.js', ''), { id: { type: DataTypes.INTEGER, autoIncrement: true, primaryKey: true, comment: 'id', }, name: { type: DataTypes.STRING, allowNull: false, defaultValue: '', comment: '名', }, img: { type: DataTypes.STRING, defaultValue: '', comment: '头像', }, phone: { type: DataTypes.STRING, defaultValue: '', comment: '电话', }, pwd: { type: DataTypes.STRING, defaultValue: '', comment: '密码', }, auth: { type: DataTypes.JSON, allowNull: false, comment: '权限', }, }, { comment: '管理员', hooks: { beforeFind(option) { if (!option.order) { option.order = [['id', 'desc']]; } }, afterFind(m) { m && (Array.isArray(m) ? m.forEach(item => formatTime(item)) : formatTime(m)); }, }, } ); module.exports = model;