|
@ -273,14 +273,21 @@ async function getMetadataModels(ctx) { |
|
|
//新建库表元数据
|
|
|
//新建库表元数据
|
|
|
async function postMetadataDatabases(ctx) { |
|
|
async function postMetadataDatabases(ctx) { |
|
|
try { |
|
|
try { |
|
|
const { name, code, catalog } = ctx.request.body; |
|
|
const { name, code, catalog, parent } = ctx.request.body; |
|
|
const models = ctx.fs.dc.models; |
|
|
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({ |
|
|
const postOne = await models.MetadataDatabase.findOne({ |
|
|
where: { $or: [{ name: name }, { code: code }], catalog: catalog } |
|
|
where: where |
|
|
}); |
|
|
}); |
|
|
if (postOne) { |
|
|
if (postOne) { |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { message: '该资源目录下元数据名称或代码已存在' } |
|
|
ctx.body = { message: '同一父节点下该元数据名称或代码已存在' } |
|
|
} else { |
|
|
} else { |
|
|
if (!name || !code || !catalog) { |
|
|
if (!name || !code || !catalog) { |
|
|
ctx.body = { message: '参数不全,请重新配置' } |
|
|
ctx.body = { message: '参数不全,请重新配置' } |
|
@ -308,10 +315,17 @@ async function putMetadataDatabases(ctx) { |
|
|
const models = ctx.fs.dc.models; |
|
|
const models = ctx.fs.dc.models; |
|
|
let metadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { id } }); |
|
|
let metadataDatabaseInfo = await models.MetadataDatabase.findOne({ where: { id } }); |
|
|
if (metadataDatabaseInfo) { |
|
|
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) { |
|
|
if (putOne) { |
|
|
ctx.status = 400; |
|
|
ctx.status = 400; |
|
|
ctx.body = { message: '该元数据名称或代码已存在' } |
|
|
ctx.body = { message: '同一父节点下该元数据名称或代码已存在' } |
|
|
} else { |
|
|
} else { |
|
|
await models.MetadataDatabase.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); |
|
|
await models.MetadataDatabase.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); |
|
|
ctx.status = 200; |
|
|
ctx.status = 200; |
|
|