From f2cdb0fe311dd34ac8d6f7d1a47b1e3f19003e2a Mon Sep 17 00:00:00 2001 From: zhangminghua Date: Tue, 28 Mar 2023 15:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E5=8D=95?= =?UTF-8?q?=E4=B8=AA=E5=BA=93=E8=A1=A8=E5=85=83=E6=95=B0=E6=8D=AE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/latestMetadata/index.js | 43 +++++++++++++++++-- api/app/lib/routes/latestMetadata/index.js | 3 ++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/latestMetadata/index.js b/api/app/lib/controllers/latestMetadata/index.js index eaacd43..5c929ec 100644 --- a/api/app/lib/controllers/latestMetadata/index.js +++ b/api/app/lib/controllers/latestMetadata/index.js @@ -114,8 +114,14 @@ async function delResourceCatalog(ctx) { async function getMetadataDatabases(ctx) { try { const models = ctx.fs.dc.models; - const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc' } = ctx.query; - const where = { catalog: catalog }; + const { catalog, limit, offset, keywords, orderBy = 'createAt', orderDirection = 'desc', id = null } = ctx.query; + const where = {}; + if (catalog) { + where.catalog = catalog; + } + if (id) { + where.parent = id; + } if (keywords) { where['$or'] = [{ name: { $iLike: `%${keywords}%` } }, { code: { $iLike: `%${keywords}%` } }, @@ -278,6 +284,36 @@ async function postMeatadataDatabases(ctx) { } } +//获取库表元数据基本信息 +async function getMetadataDatabasesById(ctx) { + try { + const models = ctx.fs.dc.models; + const { id } = ctx.params; + const findObj = { + include: [ + { + model: models.User, + attributes: ['id', 'name', 'username'], + }, + { + model: models.TagDatabase, + include: [{ + model: models.Tag, + }] + }], + where: { id: id }, + } + const rslt = await models.MetadataDatabase.findOne(findObj); + ctx.status = 200; + ctx.body = rslt; + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = { + "message": "获取库表元数据基本信息失败" + } + } +} module.exports = { getResourceCatalog, postResourceCatalog, @@ -289,5 +325,6 @@ module.exports = { getMetadataModels, postMeatadataDatabases, // putMeatadataDatabases, - // delMeatadataDatabases + // delMeatadataDatabases, + getMetadataDatabasesById } \ No newline at end of file diff --git a/api/app/lib/routes/latestMetadata/index.js b/api/app/lib/routes/latestMetadata/index.js index ced9286..0caa457 100644 --- a/api/app/lib/routes/latestMetadata/index.js +++ b/api/app/lib/routes/latestMetadata/index.js @@ -35,4 +35,7 @@ module.exports = function (app, router, opts) { // app.fs.api.logAttr['DEL /meatadata/databases/:id'] = { content: '删除库表元数据', visible: true }; // router.delete('/meatadata/databases/:id', latestMetadata.delMeatadataDatabases); + + app.fs.api.logAttr['GET/metadata/databases/:id'] = { content: '获取库表元数据基本信息', visible: false }; + router.get('/metadata/databases/:id', latestMetadata.getMetadataDatabasesById); }; \ No newline at end of file