From b52ca37a390d9332043eed9a80b2ec8eb33afcb7 Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 23 May 2023 09:42:28 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E5=BA=93=E8=A1=A8=E5=85=83=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=90=8C=E4=B8=80=E7=88=B6=E8=8A=82=E7=82=B9=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E9=87=8D=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index ea65098..e3c6010 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -273,14 +273,21 @@ async function getMetadataModels(ctx) { //新建库表元数据 async function postMetadataDatabases(ctx) { try { - const { name, code, catalog } = ctx.request.body; + const { name, code, catalog, parent } = ctx.request.body; const models = ctx.fs.dc.models; + const where = { $or: [{ name: name }, { code: code }] }; + if (parent) { + where.parent = parent; + } else { + where.parent = null; + where.catalog = catalog; + } const postOne = await models.MetadataDatabase.findOne({ - where: { $or: [{ name: name }, { code: code }], catalog: catalog } + where: where }); if (postOne) { ctx.status = 400; - ctx.body = { message: '该资源目录下元数据名称或代码已存在' } + ctx.body = { message: '同一父节点下该元数据名称或代码已存在' } } else { if (!name || !code || !catalog) { ctx.body = { message: '参数不全,请重新配置' } @@ -308,10 +315,17 @@ async function putMetadataDatabases(ctx) { const models = ctx.fs.dc.models; let metadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { id } }); if (metadataDatabaseInfo) { - const putOne = await models.MetadataDatabase.findOne({ where: { id: { $not: id }, catalog: catalog, $or: [{ name: name }, { code: code }] } }); + const where = { id: { $not: id }, $or: [{ name: name }, { code: code }] } + if (metadataDatabaseInfo.parent) { + where.parent = metadataDatabaseInfo.parent; + } else { + where.parent = null; + where.catalog = catalog; + } + const putOne = await models.MetadataDatabase.findOne({ where: where }); if (putOne) { ctx.status = 400; - ctx.body = { message: '该元数据名称或代码已存在' } + ctx.body = { message: '同一父节点下该元数据名称或代码已存在' } } else { await models.MetadataDatabase.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); ctx.status = 200;