refactor: 统一代码风格并迁移至 ESLint 新配置
style(backend): 格式化模型文件代码 style(frontend): 调整组件代码格式 chore: 删除旧 ESLint 配置并添加新配置 refactor(backend): 重构模型定义语法 style: 统一箭头函数和对象属性简写
This commit is contained in:
@@ -7,41 +7,48 @@ const createDeviceSchema = Joi.object({
|
||||
name: Joi.string().required().max(100).messages({
|
||||
'string.empty': '设备名称不能为空',
|
||||
'string.max': '设备名称不能超过100个字符',
|
||||
'any.required': '设备名称是必填字段'
|
||||
}),
|
||||
type: Joi.string().required().valid(...DEVICE_TYPES).messages({
|
||||
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
|
||||
'any.required': '设备类型是必填字段'
|
||||
'any.required': '设备名称是必填字段',
|
||||
}),
|
||||
type: Joi.string()
|
||||
.required()
|
||||
.valid(...DEVICE_TYPES)
|
||||
.messages({
|
||||
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
|
||||
'any.required': '设备类型是必填字段',
|
||||
}),
|
||||
model: Joi.string().allow('', null).max(100),
|
||||
serialNumber: Joi.string().required().max(100).messages({
|
||||
'string.empty': '序列号不能为空',
|
||||
'string.max': '序列号不能超过100个字符',
|
||||
'any.required': '序列号是必填字段'
|
||||
'any.required': '序列号是必填字段',
|
||||
}),
|
||||
rackId: Joi.string().allow('', null).max(50),
|
||||
position: Joi.number().integer().min(1).max(100).allow(null),
|
||||
height: Joi.number().integer().min(1).max(50).allow(null),
|
||||
powerConsumption: Joi.number().min(0).max(100000).allow(null),
|
||||
ipAddress: Joi.string().allow('', null).max(50),
|
||||
status: Joi.string().valid(...DEVICE_STATUS).default('offline'),
|
||||
status: Joi.string()
|
||||
.valid(...DEVICE_STATUS)
|
||||
.default('offline'),
|
||||
purchaseDate: Joi.date().allow(null),
|
||||
warrantyExpiry: Joi.date().allow(null),
|
||||
description: Joi.string().allow('', null).max(500),
|
||||
customFields: Joi.object().allow(null)
|
||||
customFields: Joi.object().allow(null),
|
||||
});
|
||||
|
||||
const updateDeviceSchema = Joi.object({
|
||||
name: Joi.string().max(100).messages({
|
||||
'string.empty': '设备名称不能为空',
|
||||
'string.max': '设备名称不能超过100个字符'
|
||||
}),
|
||||
type: Joi.string().valid(...DEVICE_TYPES).messages({
|
||||
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`
|
||||
'string.max': '设备名称不能超过100个字符',
|
||||
}),
|
||||
type: Joi.string()
|
||||
.valid(...DEVICE_TYPES)
|
||||
.messages({
|
||||
'any.only': `设备类型必须是以下之一: ${DEVICE_TYPES.join(', ')}`,
|
||||
}),
|
||||
model: Joi.string().allow('', null).max(100),
|
||||
serialNumber: Joi.string().max(100).messages({
|
||||
'string.max': '序列号不能超过100个字符'
|
||||
'string.max': '序列号不能超过100个字符',
|
||||
}),
|
||||
rackId: Joi.string().allow('', null).max(50),
|
||||
position: Joi.number().integer().min(1).max(100).allow(null),
|
||||
@@ -52,82 +59,58 @@ const updateDeviceSchema = Joi.object({
|
||||
purchaseDate: Joi.date().allow(null),
|
||||
warrantyExpiry: Joi.date().allow(null),
|
||||
description: Joi.string().allow('', null).max(500),
|
||||
customFields: Joi.object().allow(null)
|
||||
}).min(1).messages({
|
||||
'object.min': '至少需要提供一个字段进行更新'
|
||||
});
|
||||
customFields: Joi.object().allow(null),
|
||||
})
|
||||
.min(1)
|
||||
.messages({
|
||||
'object.min': '至少需要提供一个字段进行更新',
|
||||
});
|
||||
|
||||
const batchDeviceIdsSchema = Joi.object({
|
||||
deviceIds: Joi.array()
|
||||
.items(Joi.string().required())
|
||||
.min(1)
|
||||
.required()
|
||||
.messages({
|
||||
'array.base': '设备ID列表必须是数组',
|
||||
'array.min': '至少需要提供一个设备ID',
|
||||
'any.required': '设备ID列表是必填字段'
|
||||
})
|
||||
deviceIds: Joi.array().items(Joi.string().required()).min(1).required().messages({
|
||||
'array.base': '设备ID列表必须是数组',
|
||||
'array.min': '至少需要提供一个设备ID',
|
||||
'any.required': '设备ID列表是必填字段',
|
||||
}),
|
||||
});
|
||||
|
||||
const batchStatusSchema = Joi.object({
|
||||
deviceIds: Joi.array()
|
||||
.items(Joi.string().required())
|
||||
.min(1)
|
||||
.required()
|
||||
.messages({
|
||||
'array.base': '设备ID列表必须是数组',
|
||||
'array.min': '至少需要提供一个设备ID',
|
||||
'any.required': '设备ID列表是必填字段'
|
||||
}),
|
||||
deviceIds: Joi.array().items(Joi.string().required()).min(1).required().messages({
|
||||
'array.base': '设备ID列表必须是数组',
|
||||
'array.min': '至少需要提供一个设备ID',
|
||||
'any.required': '设备ID列表是必填字段',
|
||||
}),
|
||||
status: Joi.string()
|
||||
.valid(...DEVICE_STATUS)
|
||||
.required()
|
||||
.messages({
|
||||
'any.only': `状态必须是以下之一: ${DEVICE_STATUS.join(', ')}`,
|
||||
'any.required': '状态是必填字段'
|
||||
})
|
||||
'any.required': '状态是必填字段',
|
||||
}),
|
||||
});
|
||||
|
||||
const batchMoveSchema = Joi.object({
|
||||
deviceIds: Joi.array()
|
||||
.items(Joi.string().required())
|
||||
.min(1)
|
||||
.required(),
|
||||
targetRackId: Joi.string()
|
||||
.required()
|
||||
.max(50)
|
||||
.messages({
|
||||
'string.empty': '目标机柜ID不能为空',
|
||||
'any.required': '目标机柜ID是必填字段'
|
||||
}),
|
||||
startPosition: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
.allow(null)
|
||||
deviceIds: Joi.array().items(Joi.string().required()).min(1).required(),
|
||||
targetRackId: Joi.string().required().max(50).messages({
|
||||
'string.empty': '目标机柜ID不能为空',
|
||||
'any.required': '目标机柜ID是必填字段',
|
||||
}),
|
||||
startPosition: Joi.number().integer().min(1).allow(null),
|
||||
});
|
||||
|
||||
const queryDeviceSchema = Joi.object({
|
||||
keyword: Joi.string()
|
||||
.max(100)
|
||||
.allow(''),
|
||||
keyword: Joi.string().max(100).allow(''),
|
||||
status: Joi.string()
|
||||
.valid(...DEVICE_STATUS, 'all')
|
||||
.allow(''),
|
||||
type: Joi.string()
|
||||
.valid(...DEVICE_TYPES, 'all')
|
||||
.allow(''),
|
||||
rackId: Joi.string()
|
||||
.max(50)
|
||||
.allow(''),
|
||||
page: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
.default(1),
|
||||
pageSize: Joi.number()
|
||||
.integer()
|
||||
.min(1)
|
||||
.max(10000)
|
||||
.default(10)
|
||||
rackId: Joi.string().max(50).allow(''),
|
||||
roomId: Joi.string().max(50).allow(''),
|
||||
isIdle: Joi.boolean().allow('').optional(),
|
||||
page: Joi.number().integer().min(1).default(1),
|
||||
pageSize: Joi.number().integer().min(1).max(10000).default(10),
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
@@ -138,5 +121,5 @@ module.exports = {
|
||||
batchMoveSchema,
|
||||
queryDeviceSchema,
|
||||
DEVICE_TYPES,
|
||||
DEVICE_STATUS
|
||||
DEVICE_STATUS,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user