From ddd06d6ab77a3643ed7ab4dd7d72e69f7b9fec19 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Mon, 23 Oct 2023 16:50:17 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E5=88=A0=E9=99=A4=E7=82=B9?= =?UTF-8?q?=E4=BD=8D=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/device/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/api/app/lib/controllers/device/index.js b/api/app/lib/controllers/device/index.js index 0765c2f..a84fb43 100644 --- a/api/app/lib/controllers/device/index.js +++ b/api/app/lib/controllers/device/index.js @@ -119,10 +119,17 @@ function editDevice(opts) { function deleteDevice(opts) { return async function (ctx, next) { + let message = '删除设备失败' try { const models = ctx.fs.dc.models; const { id } = ctx.params; if (id) { + let exitPointDevice = await models.PointDevice.findOne({ where: { deviceId: { $in: id.split(',') } } }) + if (exitPointDevice) { + message = '该设备已绑定点位 无法删除!' + throw new Error(message) + } + await models.Device.destroy({ where: { id: { $in: id.split(',') } @@ -137,7 +144,7 @@ function deleteDevice(opts) { } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; - ctx.body = { message: '删除设备失败' } + ctx.body = { message: message } } } }