|
|
|
'use strict';
|
|
|
|
function getBackupsList(opts) {
|
|
|
|
return async function (ctx, next) {
|
|
|
|
|
|
|
|
const models = ctx.fs.dc.models;
|
|
|
|
const { page, limit, name } = ctx.query;
|
|
|
|
const Op = ctx.fs.dc.ORM.Op;
|
|
|
|
let errMsg = { message: '获取数据备份失败' }
|
|
|
|
try {
|
|
|
|
let searchWhere = {
|
|
|
|
|
|
|
|
}
|
|
|
|
let option = {
|
|
|
|
where: searchWhere,
|
|
|
|
order: [["id", "desc"]],
|
|
|
|
attributes: { exclude: ['password'] },
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name) {
|
|
|
|
searchWhere.note = { $like: '%' + name + '%' };
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
option.where = searchWhere
|
|
|
|
let limit_ = limit || 10;
|
|
|
|
let page_ = page || 1;
|
|
|
|
let offset = (page_ - 1) * limit_;
|
|
|
|
if (limit && page) {
|
|
|
|
option.limit = limit_
|
|
|
|
option.offset = offset
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await models.Backups.findAndCount(option);
|
|
|
|
ctx.status = 200;
|
|
|
|
ctx.body = res;
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = errMsg
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 新增数据备份
|
|
|
|
function addBackups(opts) {
|
|
|
|
return async function (ctx, next) {
|
|
|
|
|
|
|
|
const models = ctx.fs.dc.models;
|
|
|
|
try {
|
|
|
|
let rslt = ctx.request.body;
|
|
|
|
await models.Backups.create(Object.assign({}, rslt))
|
|
|
|
ctx.status = 204;
|
|
|
|
ctx.body = { message: '新建数据备份成功' }
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = { message: '新建数据备份失败' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 修改数据备份
|
|
|
|
function editBackups(opts) {
|
|
|
|
return async function (ctx, next) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
const models = ctx.fs.dc.models;
|
|
|
|
const { id } = ctx.params;
|
|
|
|
const body = ctx.request.body;
|
|
|
|
|
|
|
|
|
|
|
|
await models.Backups.update(
|
|
|
|
body,
|
|
|
|
{ where: { id: id, } }
|
|
|
|
)
|
|
|
|
ctx.status = 204;
|
|
|
|
ctx.body = { message: '修改数据备份成功' }
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = { message: '修改数据备份失败' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 删除数据备份
|
|
|
|
function deleteBackups(opts) {
|
|
|
|
return async function (ctx, next) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
const models = ctx.fs.dc.models;
|
|
|
|
const { id } = ctx.params;
|
|
|
|
|
|
|
|
await models.Backups.destroy({
|
|
|
|
where: {
|
|
|
|
id: id
|
|
|
|
}
|
|
|
|
})
|
|
|
|
ctx.status = 204;
|
|
|
|
ctx.body = { message: '删除数据备份成功' }
|
|
|
|
} catch (error) {
|
|
|
|
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
|
|
|
|
ctx.status = 400;
|
|
|
|
ctx.body = { message: '删除数据备份失败' }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getBackupsList,
|
|
|
|
addBackups,
|
|
|
|
editBackups,
|
|
|
|
deleteBackups,
|
|
|
|
|
|
|
|
}
|