yapi/exts/yapi-plugin-statistics/controller.js

66 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-10-25 19:33:34 +08:00
/**
* 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');
2017-10-27 12:13:59 +08:00
const interfaceCaseModel = require('models/interfaceCase.js')
2017-10-25 19:33:34 +08:00
const yapi = require('yapi.js');
const config = require('./index.js');
2017-10-27 12:13:59 +08:00
const commons = require('./util.js');
2017-10-25 19:33:34 +08:00
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);
2017-10-27 12:13:59 +08:00
this.interfaceCaseModel = yapi.getInst(interfaceCaseModel);
2017-10-25 19:33:34 +08:00
}
2017-10-27 12:13:59 +08:00
/**
* 获取所有统计总数
* @interface statismock/count
* @method get
* @category statistics
* @foldnumber 10
* @returns {Object}
*/
async getStatisCount(ctx) {
2017-10-25 19:33:34 +08:00
let groupCount = await this.groupModel.getGroupListCount();
let projectCount = await this.projectModel.getProjectListCount();
let interfaceCount = await this.interfaceModel.getInterfaceListCount();
2017-10-27 12:13:59 +08:00
let interfaceCaseCount = await this.interfaceCaseModel.getInterfaceCaseListCount();
2017-10-25 19:33:34 +08:00
2017-10-27 12:13:59 +08:00
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 mockDateList = [];
if (!this.getRole() === 'admin') {
return ctx.body = yapi.commons.resReturn(null, 405, '没有权限');
}
// 默认时间是30 天为一周期
let dateInterval = commons.getDateRange();
mockDateList = await this.Model.getDayCount(dateInterval);
return ctx.body = yapi.commons.resReturn({ mockCount, mockDateList });
2017-10-25 19:33:34 +08:00
}
}
2017-10-27 12:13:59 +08:00
2017-10-25 19:33:34 +08:00
module.exports = statisMockController;