'use strict'; const moment = require('moment') function getSpecifications (opts) { return async function (ctx, next) { const models = ctx.fs.dc.models; const { page, limit, keyword, } = ctx.query; let errMsg = { message: '查询数据安全规范列表失败' } try { let option = { where: {}, order: [["id", "desc"]], } if (keyword) { option.where.fileName = { $iLike: `%${keyword}%` } } if (limit) { option.limit = Number(limit) } if (page && limit) { option.offset = Number(page) * Number(limit) } const res = await models.DataSecuritySpecification.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 delSpecifications (opts) { return async function (ctx, next) { try { const models = ctx.fs.dc.models; const { fileIds } = ctx.params; await models.DataSecuritySpecification.destroy({ where: { id: { $in: fileIds.split(',') } } }) ctx.status = 204; ctx.body = { message: '删除数据安全规范文件成功' } } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: '删除数据安全规范文件失败' } } } } // 新增标准文档 function postSpecifications (opts) { return async function (ctx, next) { let message = '新增数据安全规范失败' try { const models = ctx.fs.dc.models; const { fileName, tags, path } = ctx.request.body; let findOne = await models.DataSecuritySpecification.findOne({ where: { fileName } }) if (findOne) { message = '文件名重复' throw '' } await models.DataSecuritySpecification.create({ fileName, tags, path, createAt: moment().format('YYYY-MM-DD HH:mm:ss') }) ctx.status = 204; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: message } } } } module.exports = { getSpecifications, postSpecifications, delSpecifications }