From 18865b621667494c97bc03ff5c04783676462d85 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Mon, 20 Mar 2023 17:07:57 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E7=BC=96=E8=BE=91=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/modelManagement/index.js | 24 ++++++++++++++----- .../containers/metaModelManagement.js | 9 +++++-- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/api/app/lib/controllers/modelManagement/index.js b/api/app/lib/controllers/modelManagement/index.js index d8a526c..b394252 100644 --- a/api/app/lib/controllers/modelManagement/index.js +++ b/api/app/lib/controllers/modelManagement/index.js @@ -75,12 +75,24 @@ function editModelManagement(opts) { const models = ctx.fs.dc.models; const { id } = ctx.params; const body = ctx.request.body; - await models.MetaModel.update( - body, - { where: { id: id, } } - ) - ctx.status = 204; - ctx.body = { message: '修改模型成功' } + let modelFind = await models.MetaModel.findOne({ where: { id: id } }); + const { attributeName, attributeCode } = ctx.request.body; + const { modelType } = modelFind; + const checkName = await models.MetaModel.findOne({ where: { id: { $not: id }, attributeName, modelType } }); + const checkCode = await models.MetaModel.findOne({ where: { id: { $not: id }, attributeCode, modelType } }); + if (checkName || checkCode) { + ctx.status = 400; + ctx.body = { message: checkName ? '该属性名称已存在' : "该属性代码已存在" } + } else { + await models.MetaModel.update( + body, + { where: { id: id, } } + ) + ctx.status = 204; + ctx.body = { message: '修改模型成功' } + } + + } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; diff --git a/web/client/src/sections/metadataManagement/containers/metaModelManagement.js b/web/client/src/sections/metadataManagement/containers/metaModelManagement.js index 66beff5..790ff60 100644 --- a/web/client/src/sections/metadataManagement/containers/metaModelManagement.js +++ b/web/client/src/sections/metadataManagement/containers/metaModelManagement.js @@ -36,8 +36,13 @@ function MetaModelManagement(props) { const dataToSave = { ...values } return dispatch( actions.metadataManagement.modifyMetaModel(editData.id, dataToSave, values?.msg || ''), - ).then(() => { - queryData(); + ).then((res) => { + if (res.success) { + queryData(); + return true; + } else { + return false; + } }); }