yapi/server/models/log.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

const yapi = require('../yapi.js');
const baseModel = require('./base.js');
// const userModel = require('../models/user.js');
2017-07-20 20:30:24 +08:00
class logModel extends baseModel {
getName() {
2017-07-20 20:30:24 +08:00
return 'log';
}
getSchema() {
return {
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 },
content: { type: String, required: true },
username: { type: String, required: true },
add_time: Number
};
}
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-20 20:30:24 +08:00
return log.save();
}
2017-08-09 16:08:37 +08:00
del(id) {
return this.model.deleteOne({
_id: id
});
}
2017-08-11 17:49:47 +08:00
list(typeid,type) {
return this.model.find({
2017-08-11 17:49:47 +08:00
typeid: typeid,
type: type
})
.exec();
}
2017-08-09 16:08:37 +08:00
2017-08-11 17:49:47 +08:00
listWithPaging(typeid,type, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
2017-08-14 15:17:05 +08:00
type: type,
typeid: typeid
}).sort({add_time:-1}).skip((page - 1) * limit).limit(limit).exec();
}
2017-08-11 17:49:47 +08:00
listCount(typeid,type) {
return this.model.count({
2017-08-11 17:49:47 +08:00
typeid: typeid,
type: type
});
}
}
2017-07-20 20:30:24 +08:00
module.exports = logModel;