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.
137 lines
3.2 KiB
137 lines
3.2 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: {
|
|
code: table,
|
|
},
|
|
order: [["id", "desc"]],
|
|
include: [{
|
|
model: models.MetadataDatabase,
|
|
where: { code: fields, },
|
|
distinct: true
|
|
|
|
}],
|
|
distinct: true
|
|
}
|
|
|
|
|
|
let list = await models.MetadataDatabase.findOne(option)
|
|
let res = await models.MetadataDatabase.findAll({
|
|
where: {
|
|
type: '字段',
|
|
parent: list && list.metadataDatabases[0] && list.metadataDatabases[0].id
|
|
}
|
|
})
|
|
|
|
|
|
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
|
|
|
|
}
|