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.
88 lines
2.0 KiB
88 lines
2.0 KiB
2 years ago
|
'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"]],
|
||
|
}
|
||
|
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, endbled } = ctx.request.body;
|
||
|
|
||
|
await models.RestfulApi.update({ name, endbled }, { 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服务失败' }
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
getServiceManagement,
|
||
|
postServiceManagement,
|
||
|
delServiceManagement
|
||
|
|
||
|
}
|