|
|
@ -499,8 +499,8 @@ async function getTagMetadata(ctx) { |
|
|
|
//申请资源
|
|
|
|
async function postMetadataResourceApplications(ctx) { |
|
|
|
try { |
|
|
|
const { resourceName, applyBy } = ctx.request.body; |
|
|
|
if (!resourceName || !applyBy) { |
|
|
|
const { resourceName, applyBy, resourceType } = ctx.request.body; |
|
|
|
if (!resourceName || !applyBy || !resourceType) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '参数不全,请重新申请资源' } |
|
|
|
} else { |
|
|
@ -577,13 +577,12 @@ async function postMetadataFiles(ctx) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//修改文件元数据
|
|
|
|
async function putMetadataFiles(ctx) { |
|
|
|
try { |
|
|
|
const { id } = ctx.params; |
|
|
|
const { updateFileName } = ctx.query; |
|
|
|
const { catalog, name } = ctx.request.body; |
|
|
|
const { catalog, name, type } = ctx.request.body; |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
let metadataFileInfo = await models.MetadataFile.findOne({ where: { id } }); |
|
|
|
if (metadataFileInfo) { |
|
|
@ -591,14 +590,19 @@ async function putMetadataFiles(ctx) { |
|
|
|
await models.MetadataFile.update({ updateAt: moment(), fileName: null }, { where: { id: id } }); |
|
|
|
ctx.status = 204; |
|
|
|
} else { |
|
|
|
const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); |
|
|
|
if (putOne) { |
|
|
|
if (!name || !catalog || !type) { |
|
|
|
ctx.body = { message: '参数不全,请重新配置' } |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据名称已存在' } |
|
|
|
} else { |
|
|
|
await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { message: '修改元数据成功' } |
|
|
|
const putOne = await models.MetadataFile.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); |
|
|
|
if (putOne) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据名称已存在' } |
|
|
|
} else { |
|
|
|
await models.MetadataFile.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { message: '修改元数据成功' } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
@ -660,6 +664,118 @@ async function delMetadataFiles(ctx) { |
|
|
|
ctx.body = { message: '删除元数据失败' } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//新建接口元数据
|
|
|
|
async function postMetadataRestapis(ctx) { |
|
|
|
try { |
|
|
|
const { name, catalog, method, url } = ctx.request.body; |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
const postOne = await models.MetadataRestapi.findOne({ |
|
|
|
where: { name: name, catalog: catalog } |
|
|
|
}); |
|
|
|
if (postOne) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该资源目录下元数据名称已存在' } |
|
|
|
} else { |
|
|
|
if (!name || !catalog || !method || !url) { |
|
|
|
ctx.body = { message: '参数不全,请重新配置' } |
|
|
|
ctx.status = 400; |
|
|
|
} else { |
|
|
|
await models.MetadataRestapi.create({ createAt: moment(), ...ctx.request.body }); |
|
|
|
ctx.body = { message: '新建元数据成功' } |
|
|
|
ctx.status = 200; |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
"message": "新建元数据失败" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//修改接口元数据
|
|
|
|
async function putMetadataRestapis(ctx) { |
|
|
|
try { |
|
|
|
const { id } = ctx.params; |
|
|
|
const { catalog, name, method, url } = ctx.request.body; |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
let metadataRestapiInfo = await models.MetadataRestapi.findOne({ where: { id } }); |
|
|
|
if (metadataRestapiInfo) { |
|
|
|
if (!name || !catalog || !method || !url) { |
|
|
|
ctx.body = { message: '参数不全,请重新修改' } |
|
|
|
ctx.status = 400; |
|
|
|
} else { |
|
|
|
const putOne = await models.MetadataRestapi.findOne({ where: { id: { $not: id }, catalog: catalog, name: name } }); |
|
|
|
if (putOne) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据名称已存在' } |
|
|
|
} else { |
|
|
|
await models.MetadataRestapi.update({ updateAt: moment(), ...ctx.request.body }, { where: { id: id } }); |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { message: '修改元数据成功' } |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据不存在' } |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { |
|
|
|
"message": "修改元数据失败" |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//删除接口元数据
|
|
|
|
async function delMetadataRestapis(ctx) { |
|
|
|
const transaction = await ctx.fs.dc.orm.transaction(); |
|
|
|
try { |
|
|
|
const models = ctx.fs.dc.models; |
|
|
|
const { id } = ctx.params; |
|
|
|
let metadataRestapiInfo = await models.MetadataRestapi.findOne({ where: { id } }); |
|
|
|
if (metadataRestapiInfo) { |
|
|
|
let deletable = true; |
|
|
|
let tagRestapiInfo = await models.TagRestapi.findOne({ where: { restapi: id } }); |
|
|
|
if (tagRestapiInfo) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据已被打标' } |
|
|
|
deletable = false; |
|
|
|
} else { |
|
|
|
let resourceConsumptionInfo = await models.ResourceConsumption.findOne({ |
|
|
|
where: { |
|
|
|
resourceName: metadataFileInfo.name, |
|
|
|
resourceType: '接口' |
|
|
|
} |
|
|
|
}); |
|
|
|
if (resourceConsumptionInfo) { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据存在资源申请' } |
|
|
|
deletable = false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (deletable) { |
|
|
|
await models.MetadataRestapi.destroy({ |
|
|
|
where: { id: id }, |
|
|
|
transaction |
|
|
|
}) |
|
|
|
await transaction.commit(); |
|
|
|
ctx.status = 200; |
|
|
|
ctx.body = { message: '删除元数据成功' } |
|
|
|
} |
|
|
|
} else { |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '该元数据不存在' } |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
await transaction.rollback(); |
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|
|
|
ctx.status = 400; |
|
|
|
ctx.body = { message: '删除元数据失败' } |
|
|
|
} |
|
|
|
} |
|
|
|
module.exports = { |
|
|
|
getResourceCatalog, |
|
|
|
postResourceCatalog, |
|
|
@ -679,5 +795,8 @@ module.exports = { |
|
|
|
getMetadataResourceApplications, |
|
|
|
postMetadataFiles, |
|
|
|
putMetadataFiles, |
|
|
|
delMetadataFiles |
|
|
|
delMetadataFiles, |
|
|
|
postMetadataRestapis, |
|
|
|
putMetadataRestapis, |
|
|
|
delMetadataRestapis |
|
|
|
} |