yapi/exts/yapi-plugin-statistics/controller.js
2017-10-27 12:13:59 +08:00

73 lines
2.4 KiB
JavaScript

/**
* Created by gxl.gao on 2017/10/24.
*/
const baseController = require('controllers/base.js');
const statisMockModel = require('./statisMockModel.js');
const groupModel = require('models/group.js');
const projectModel = require('models/project.js');
const interfaceModel = require('models/interface.js');
const interfaceCaseModel = require('models/interfaceCase.js')
const yapi = require('yapi.js');
const config = require('./index.js');
const commons = require('./util.js');
class statisMockController extends baseController {
constructor(ctx) {
super(ctx);
this.Model = yapi.getInst(statisMockModel);
this.groupModel = yapi.getInst(groupModel);
this.projectModel = yapi.getInst(projectModel);
this.interfaceModel = yapi.getInst(interfaceModel);
this.interfaceCaseModel = yapi.getInst(interfaceCaseModel);
}
/**
* 获取所有统计总数
* @interface statismock/count
* @method get
* @category statistics
* @foldnumber 10
* @returns {Object}
*/
async getStatisCount(ctx) {
// let id = ctx.query.interface_id;
// let mockData = await this.Model.get(id);
let groupCount = await this.groupModel.getGroupListCount();
let projectCount = await this.projectModel.getProjectListCount();
let interfaceCount = await this.interfaceModel.getInterfaceListCount();
let interfaceCaseCount = await this.interfaceCaseModel.getInterfaceCaseListCount();
// if(!mockData){
// return ctx.body = yapi.commons.resReturn(null, 408, 'mock脚本不存在');
// }
return ctx.body = yapi.commons.resReturn({ groupCount, projectCount, interfaceCount, interfaceCaseCount });
}
/**
* 获取所有mock接口数据信息
* @interface statismock/get
* @method get
* @category statistics
* @foldnumber 10
* @returns {Object}
*/
async getMockDateList(ctx) {
let mockCount = await this.Model.getTotalCount();
// let list = await this.Model.list();
let mockDateList = [];
if (!this.getRole() === 'admin') {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
// 默认时间是30 天为一周期
let dateInterval = commons.getDateRange();
// console.log('interval', dateInterval);
mockDateList = await this.Model.getDayCount(dateInterval);
return ctx.body = yapi.commons.resReturn({ mockCount, mockDateList });
}
}
module.exports = statisMockController;