政务数据资源中心(Government data Resource center) 03专项3期主要建设内容
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 lines
3.3 KiB

'use strict';
const moment = require('moment')
//获取REST服务失败
function getServiceManagement (opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
const { page, limit, keyword } = ctx.query;
try {
let option = {
where: {},
order: [["id", "desc"]],
include: [{
model: models.ResourceConsumption,
}],
distinct: true
}
if (keyword) {
option.where.name = { $iLike: `%${keyword}%` }
}
if (limit) {
option.limit = Number(limit)
}
if (page && limit) {
option.offset = Number(page) * Number(limit)
}
let res = await models.RestfulApi.findAndCount(option)
ctx.status = 200;
ctx.body = res
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '获取REST服务失败' }
}
}
}
//编辑REST服务
function postServiceManagement (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id, name, enabled } = ctx.request.body;
await models.RestfulApi.update({ name: name, enabled: enabled }, { where: { id: id } })
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '编辑REST服务失败' }
}
}
}
//编辑REST服务
function delServiceManagement (opts) {
return async function (ctx, next) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.RestfulApi.destroy({
where: {
id: id
}
})
ctx.status = 204;
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '删除REST服务失败' }
}
}
}
//获取表字段
function getLookField (opts) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
const { table, fields } = ctx.query;
try {
let option = {
where: {
$or: []
// code: table,
// 'metadataDatabase.code': fields
},
order: [["id", "desc"]],
include: [{
model: models.MetadataDatabase,
include: [{
model: models.MetadataDatabase,
}],
distinct: true
}],
distinct: true
}
option.where.$or.push(
{
code: table,
}
)
option.where.$or.push(
{
'$metadataDatabase.code$': fields
},
)
let res = await models.MetadataDatabase.findOne(option)
ctx.status = 200;
ctx.body = res
} catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = { message: '获取表字段失败' }
}
}
}
module.exports = {
getServiceManagement,
postServiceManagement,
delServiceManagement,
getLookField
}