refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码 style(frontend): 调整组件代码格式 chore: 删除旧 ESLint 配置并添加新配置 refactor(backend): 重构模型定义语法 style: 统一箭头函数和对象属性简写
This commit is contained in:
+62
-58
@@ -2,66 +2,70 @@ const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../db');
|
||||
const Device = require('./Device');
|
||||
|
||||
const Cable = sequelize.define('Cable', {
|
||||
cableId: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true
|
||||
const Cable = sequelize.define(
|
||||
'Cable',
|
||||
{
|
||||
cableId: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
sourceDeviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'devices',
|
||||
key: 'deviceId',
|
||||
},
|
||||
},
|
||||
sourcePort: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
targetDeviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'devices',
|
||||
key: 'deviceId',
|
||||
},
|
||||
},
|
||||
targetPort: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
cableType: {
|
||||
type: DataTypes.ENUM('ethernet', 'fiber', 'copper'),
|
||||
defaultValue: 'ethernet',
|
||||
allowNull: false,
|
||||
},
|
||||
cableLength: {
|
||||
type: DataTypes.DECIMAL(5, 2),
|
||||
allowNull: true,
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('normal', 'fault', 'disconnected'),
|
||||
defaultValue: 'normal',
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
sourceDeviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'devices',
|
||||
key: 'deviceId'
|
||||
}
|
||||
},
|
||||
sourcePort: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
targetDeviceId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'devices',
|
||||
key: 'deviceId'
|
||||
}
|
||||
},
|
||||
targetPort: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
cableType: {
|
||||
type: DataTypes.ENUM('ethernet', 'fiber', 'copper'),
|
||||
defaultValue: 'ethernet',
|
||||
allowNull: false
|
||||
},
|
||||
cableLength: {
|
||||
type: DataTypes.DECIMAL(5, 2),
|
||||
allowNull: true
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('normal', 'fault', 'disconnected'),
|
||||
defaultValue: 'normal',
|
||||
allowNull: false
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.TEXT,
|
||||
allowNull: true
|
||||
{
|
||||
tableName: 'cables',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{ fields: ['sourceDeviceId'] },
|
||||
{ fields: ['targetDeviceId'] },
|
||||
{ fields: ['status'] },
|
||||
{ fields: ['cableType'] },
|
||||
{ fields: ['sourceDeviceId', 'targetDeviceId'] },
|
||||
],
|
||||
}
|
||||
}, {
|
||||
tableName: 'cables',
|
||||
timestamps: true,
|
||||
indexes: [
|
||||
{ fields: ['sourceDeviceId'] },
|
||||
{ fields: ['targetDeviceId'] },
|
||||
{ fields: ['status'] },
|
||||
{ fields: ['cableType'] },
|
||||
{ fields: ['sourceDeviceId', 'targetDeviceId'] }
|
||||
]
|
||||
});
|
||||
);
|
||||
|
||||
Cable.belongsTo(Device, { foreignKey: 'sourceDeviceId', as: 'sourceDevice' });
|
||||
Cable.belongsTo(Device, { foreignKey: 'targetDeviceId', as: 'targetDevice' });
|
||||
|
||||
Reference in New Issue
Block a user