yapi/server/models/log.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

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 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 16:08:37 +08:00
groupid: { type: Number, required: true },
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-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-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-09 16:08:37 +08:00
list(groupid) {
return this.model.find({
2017-08-09 16:08:37 +08:00
groupid: groupid
})
.exec();
}
2017-08-09 16:08:37 +08:00
2017-08-09 16:08:37 +08:00
listWithPaging(groupid, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
2017-08-09 16:08:37 +08:00
groupid: groupid
}).skip((page - 1) * limit).limit(limit).exec();
}
2017-08-09 16:08:37 +08:00
listCount(groupid) {
return this.model.count({
2017-08-09 16:08:37 +08:00
groupid: groupid
});
}
}
2017-07-20 20:30:24 +08:00
module.exports = logModel;