2017-09-03 08:43:13 +08:00
|
|
|
|
const yapi = require('../yapi.js');
|
|
|
|
|
const baseModel = require('./base.js');
|
|
|
|
|
// const userModel = require('../models/user.js');
|
2017-07-20 19:21:46 +08:00
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
class logModel extends baseModel {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
getName() {
|
2017-07-20 20:30:24 +08:00
|
|
|
|
return 'log';
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getSchema() {
|
|
|
|
|
return {
|
2017-07-26 22:03:18 +08:00
|
|
|
|
uid: { type: Number, required: true },
|
2017-08-09 18:00:45 +08:00
|
|
|
|
typeid: { type: Number, required: true },
|
2017-08-09 16:08:37 +08:00
|
|
|
|
type: { type: String,enum:['user', 'group', 'interface','project', 'other', 'interface_col'], required: true },
|
2017-07-26 22:03:18 +08:00
|
|
|
|
content: { type: String, required: true },
|
|
|
|
|
username: { type: String, required: true },
|
2017-07-20 19:21:46 +08:00
|
|
|
|
add_time: Number
|
2017-07-26 22:03:18 +08:00
|
|
|
|
};
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-24 12:25:46 +08:00
|
|
|
|
/**
|
|
|
|
|
* @param {String} content log内容
|
|
|
|
|
* @param {Enum} type log类型, ['user', 'group', 'interface', 'project', 'other']
|
|
|
|
|
* @param {Number} uid 用户id
|
2017-08-11 17:49:47 +08:00
|
|
|
|
* @param {String} username 用户名
|
|
|
|
|
* @param {Number} typeid 类型id
|
|
|
|
|
* @param {Number} add_time 时间
|
2017-07-24 12:25:46 +08:00
|
|
|
|
*/
|
2017-08-09 16:08:37 +08:00
|
|
|
|
save(data) {
|
2017-07-20 20:30:24 +08:00
|
|
|
|
let saveData = {
|
|
|
|
|
content: data.content,
|
|
|
|
|
type: data.type,
|
|
|
|
|
uid: data.uid,
|
2017-08-09 16:08:37 +08:00
|
|
|
|
username: data.username,
|
2017-08-09 18:00:45 +08:00
|
|
|
|
typeid: data.typeid,
|
2017-07-20 20:30:24 +08:00
|
|
|
|
add_time: yapi.commons.time()
|
|
|
|
|
};
|
|
|
|
|
let log = new this.model(saveData);
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
return log.save();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
2017-08-09 16:08:37 +08:00
|
|
|
|
|
|
|
|
|
del(id) {
|
|
|
|
|
return this.model.deleteOne({
|
|
|
|
|
_id: id
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-07-20 19:21:46 +08:00
|
|
|
|
|
2017-08-11 17:49:47 +08:00
|
|
|
|
list(typeid,type) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.find({
|
2017-08-11 17:49:47 +08:00
|
|
|
|
typeid: typeid,
|
|
|
|
|
type: type
|
2017-07-26 22:03:18 +08:00
|
|
|
|
})
|
|
|
|
|
.exec();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
2017-08-09 16:08:37 +08:00
|
|
|
|
|
2017-07-20 19:21:46 +08:00
|
|
|
|
|
2017-08-11 17:49:47 +08:00
|
|
|
|
listWithPaging(typeid,type, page, limit) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
page = parseInt(page);
|
|
|
|
|
limit = parseInt(limit);
|
2017-07-26 22:03:18 +08:00
|
|
|
|
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.find({
|
2017-08-14 15:17:05 +08:00
|
|
|
|
type: type,
|
|
|
|
|
typeid: typeid
|
2017-08-23 10:55:17 +08:00
|
|
|
|
}).sort({add_time:-1}).skip((page - 1) * limit).limit(limit).exec();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-11 17:49:47 +08:00
|
|
|
|
listCount(typeid,type) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.count({
|
2017-08-11 17:49:47 +08:00
|
|
|
|
typeid: typeid,
|
|
|
|
|
type: type
|
2017-07-20 19:21:46 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
module.exports = logModel;
|