Browse Source

(*)库表元数据同一父节点下不重名

master
zmh 2 years ago
parent
commit
b52ca37a39
  1. 24
      api/app/lib/controllers/latestMetadata/index.js

24
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;

Loading…
Cancel
Save