2017-07-20 20:30:24 +08:00
|
|
|
|
import logModel from '../models/log.js';
|
|
|
|
|
import yapi from '../yapi.js';
|
|
|
|
|
import baseController from './base.js';
|
|
|
|
|
import groupModel from '../models/group';
|
|
|
|
|
|
|
|
|
|
class logController extends baseController {
|
|
|
|
|
constructor(ctx) {
|
|
|
|
|
super(ctx);
|
|
|
|
|
this.Model = yapi.getInst(logModel);
|
|
|
|
|
this.groupModel = yapi.getInst(groupModel);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-10 15:47:33 +08:00
|
|
|
|
* 获取动态列表
|
|
|
|
|
* @interface /log/list
|
2017-07-20 20:30:24 +08:00
|
|
|
|
* @method GET
|
2017-08-10 15:47:33 +08:00
|
|
|
|
* @category log
|
2017-07-20 20:30:24 +08:00
|
|
|
|
* @foldnumber 10
|
2017-08-11 17:49:47 +08:00
|
|
|
|
* @param {Number} typeid 动态类型id, 不能为空
|
2017-07-20 20:30:24 +08:00
|
|
|
|
* @param {Number} [page] 分页页码
|
|
|
|
|
* @param {Number} [limit] 分页大小
|
|
|
|
|
* @returns {Object}
|
2017-08-10 15:47:33 +08:00
|
|
|
|
* @example /log/list
|
2017-07-20 20:30:24 +08:00
|
|
|
|
*/
|
2017-08-09 16:08:37 +08:00
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
async list(ctx) {
|
2017-08-09 18:00:45 +08:00
|
|
|
|
let typeid = ctx.request.query.typeid,
|
2017-07-20 20:30:24 +08:00
|
|
|
|
page = ctx.request.query.page || 1,
|
2017-08-11 17:49:47 +08:00
|
|
|
|
limit = ctx.request.query.limit || 10,
|
|
|
|
|
type = ctx.request.query.type;
|
2017-08-09 18:00:45 +08:00
|
|
|
|
if (!typeid) {
|
2017-08-10 12:13:32 +08:00
|
|
|
|
return ctx.body = yapi.commons.resReturn(null, 400, 'typeid不能为空');
|
2017-07-20 20:30:24 +08:00
|
|
|
|
}
|
2017-08-11 17:49:47 +08:00
|
|
|
|
if(!type) {
|
|
|
|
|
return ctx.body = yapi.commons.resReturn(null, 400, 'type不能为空');
|
|
|
|
|
}
|
2017-07-20 20:30:24 +08:00
|
|
|
|
try {
|
2017-08-11 17:49:47 +08:00
|
|
|
|
let result = await this.Model.listWithPaging(typeid,type, page, limit);
|
|
|
|
|
let count = await this.Model.listCount(typeid,type);
|
2017-07-27 19:49:26 +08:00
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
ctx.body = yapi.commons.resReturn({
|
|
|
|
|
total: Math.ceil(count / limit),
|
|
|
|
|
list: result
|
2017-07-27 19:49:26 +08:00
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
ctx.body = yapi.commons.resReturn(null, 402, err.message);
|
2017-07-20 20:30:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = logController;
|