liujiangyong 1 year ago
parent
commit
356a2a436b
  1. 9
      api/app/lib/controllers/device/index.js

9
api/app/lib/controllers/device/index.js

@ -119,10 +119,17 @@ function editDevice(opts) {
function deleteDevice(opts) { function deleteDevice(opts) {
return async function (ctx, next) { return async function (ctx, next) {
let message = '删除设备失败'
try { try {
const models = ctx.fs.dc.models; const models = ctx.fs.dc.models;
const { id } = ctx.params; const { id } = ctx.params;
if (id) { if (id) {
let exitPointDevice = await models.PointDevice.findOne({ where: { deviceId: { $in: id.split(',') } } })
if (exitPointDevice) {
message = '该设备已绑定点位 无法删除!'
throw new Error(message)
}
await models.Device.destroy({ await models.Device.destroy({
where: { where: {
id: { $in: id.split(',') } id: { $in: id.split(',') }
@ -137,7 +144,7 @@ function deleteDevice(opts) {
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400; ctx.status = 400;
ctx.body = { message: '删除设备失败' } ctx.body = { message: message }
} }
} }
} }

Loading…
Cancel
Save