refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码 style(frontend): 调整组件代码格式 chore: 删除旧 ESLint 配置并添加新配置 refactor(backend): 重构模型定义语法 style: 统一箭头函数和对象属性简写
This commit is contained in:
@@ -3,52 +3,56 @@ const { sequelize } = require('../db');
|
||||
const Device = require('./Device');
|
||||
const Business = require('./Business');
|
||||
|
||||
const DeviceBusiness = sequelize.define('DeviceBusiness', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true
|
||||
const DeviceBusiness = sequelize.define(
|
||||
'DeviceBusiness',
|
||||
{
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
deviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Device,
|
||||
key: 'deviceId',
|
||||
},
|
||||
},
|
||||
businessId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Business,
|
||||
key: 'businessId',
|
||||
},
|
||||
},
|
||||
isPrimary: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
},
|
||||
},
|
||||
deviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Device,
|
||||
key: 'deviceId'
|
||||
}
|
||||
},
|
||||
businessId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: Business,
|
||||
key: 'businessId'
|
||||
}
|
||||
},
|
||||
isPrimary: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false
|
||||
{
|
||||
tableName: 'device_business',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{ fields: ['deviceId'] },
|
||||
{ fields: ['businessId'] },
|
||||
{ unique: true, fields: ['deviceId', 'businessId'] },
|
||||
],
|
||||
}
|
||||
}, {
|
||||
tableName: 'device_business',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{ fields: ['deviceId'] },
|
||||
{ fields: ['businessId'] },
|
||||
{ unique: true, fields: ['deviceId', 'businessId'] }
|
||||
]
|
||||
});
|
||||
);
|
||||
|
||||
Device.belongsToMany(Business, {
|
||||
through: DeviceBusiness,
|
||||
foreignKey: 'deviceId',
|
||||
otherKey: 'businessId'
|
||||
otherKey: 'businessId',
|
||||
});
|
||||
|
||||
Business.belongsToMany(Device, {
|
||||
through: DeviceBusiness,
|
||||
foreignKey: 'businessId',
|
||||
otherKey: 'deviceId'
|
||||
otherKey: 'deviceId',
|
||||
});
|
||||
|
||||
DeviceBusiness.belongsTo(Business, { foreignKey: 'businessId' });
|
||||
|
||||
Reference in New Issue
Block a user