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.
55 lines
1.5 KiB
55 lines
1.5 KiB
import { Sequelize, DataTypes, Optional, Model } from "sequelize"
|
|
|
|
interface ColorAttributes {
|
|
id: number
|
|
name: string
|
|
value: string
|
|
desctibe: string
|
|
|
|
createdAt?: Date
|
|
updatedAt?: Date
|
|
deletedAt?: Date
|
|
}
|
|
|
|
export interface ColorInput extends Optional<ColorAttributes, "id"> { }
|
|
export interface ColorOutput extends Required<ColorAttributes> { }
|
|
export type TColorModel = ReturnType<typeof ColorModel>
|
|
|
|
export default function ColorModel(sequelize: Sequelize) {
|
|
interface UserInstance
|
|
extends Model<ColorAttributes, ColorInput>,
|
|
ColorAttributes { }
|
|
const Color = sequelize.define<UserInstance>("color", {
|
|
id: {
|
|
type: DataTypes.INTEGER,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
name: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
value: {
|
|
type: DataTypes.STRING,
|
|
allowNull: false,
|
|
},
|
|
desctibe: {
|
|
type: DataTypes.STRING,
|
|
},
|
|
}, {
|
|
underscored: true,
|
|
deletedAt: true,
|
|
paranoid: true,
|
|
timestamps: true,
|
|
})
|
|
// 覆盖Color的toJSON方法
|
|
Color.prototype.toJSON = function () {
|
|
const values = Object.assign({}, this.get()) as ColorAttributes
|
|
delete values.deletedAt
|
|
return values
|
|
}
|
|
Color.associate = function (models) {
|
|
models["color"].hasMany(models["color_cate"])
|
|
models["color_cate"].belongsTo(models["color"])
|
|
}
|
|
return Color
|
|
}
|
|
|