2017-07-20 19:21:46 +08:00
|
|
|
|
import yapi from '../yapi.js';
|
|
|
|
|
import baseModel from './base.js';
|
2017-08-09 16:08:37 +08:00
|
|
|
|
// import userModel from '../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 16:08:37 +08:00
|
|
|
|
groupid: { type: Number, required: true },
|
|
|
|
|
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-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,
|
|
|
|
|
groupid: data.groupid,
|
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-09 16:08:37 +08:00
|
|
|
|
list(groupid) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.find({
|
2017-08-09 16:08:37 +08:00
|
|
|
|
groupid: groupid
|
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-09 16:08:37 +08:00
|
|
|
|
listWithPaging(groupid, 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-09 16:08:37 +08:00
|
|
|
|
groupid: groupid
|
|
|
|
|
}).skip((page - 1) * limit).limit(limit).exec();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-09 16:08:37 +08:00
|
|
|
|
listCount(groupid) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.count({
|
2017-08-09 16:08:37 +08:00
|
|
|
|
groupid: groupid
|
2017-07-20 19:21:46 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
module.exports = logModel;
|