yapi/server/controllers/log.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

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-09 16:08:37 +08:00
try{
// var res = this.Model.save({
// uid: 107,
2017-08-09 18:00:45 +08:00
// typeid: 21,
2017-08-09 16:08:37 +08:00
// type: 'project',
2017-08-09 18:00:45 +08:00
// username: '小明明宝宝',
// content: '小明应该修改了的项目宝宝',
2017-08-09 16:08:37 +08:00
// time: yapi.commons.time()
// });
// var res = this.Model.del(107);
// ctx.body = yapi.commons.resReturn(null, 200,res);
}catch(err){
// ctx.body = yapi.commons.resReturn(null, 402, err.message);
}
2017-07-20 20:30:24 +08:00
}
/**
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
* @param {Number} uid 用户id 不能为空
* @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,
limit = ctx.request.query.limit || 10;
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
}
try {
2017-08-09 18:00:45 +08:00
let result = await this.Model.listWithPaging(typeid, page, limit);
let count = await this.Model.listCount(typeid);
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;