2017-07-20 19:21:46 +08:00
|
|
|
|
import yapi from '../yapi.js';
|
|
|
|
|
import baseModel from './base.js';
|
2017-07-20 20:30:24 +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 },
|
|
|
|
|
title: { type: String, required: true },
|
|
|
|
|
type: { type: String, enum: ['user', 'group', 'interface', 'project', 'other'], required: true },
|
|
|
|
|
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} title log标题
|
|
|
|
|
* @param {String} content log内容
|
|
|
|
|
* @param {Enum} type log类型, ['user', 'group', 'interface', 'project', 'other']
|
|
|
|
|
* @param {Number} uid 用户id
|
|
|
|
|
*/
|
2017-07-20 20:30:24 +08:00
|
|
|
|
async save(data) {
|
|
|
|
|
let userInst = yapi.getInst(userModel);
|
|
|
|
|
let username = await userInst.findById(data.uid);
|
|
|
|
|
let saveData = {
|
|
|
|
|
title: data.title,
|
|
|
|
|
content: data.content,
|
|
|
|
|
type: data.type,
|
|
|
|
|
uid: data.uid,
|
|
|
|
|
username: username,
|
|
|
|
|
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-07-26 22:03:18 +08:00
|
|
|
|
list(uid) {
|
2017-07-20 19:21:46 +08:00
|
|
|
|
return this.model.find({
|
|
|
|
|
uid: uid
|
2017-07-26 22:03:18 +08:00
|
|
|
|
})
|
|
|
|
|
.exec();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listWithPaging(uid, page, limit) {
|
|
|
|
|
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({
|
|
|
|
|
uid: uid
|
2017-07-26 22:03:18 +08:00
|
|
|
|
})
|
|
|
|
|
.skip((page - 1) * limit)
|
|
|
|
|
.limit(limit)
|
|
|
|
|
.exec();
|
2017-07-20 19:21:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listCount(uid) {
|
|
|
|
|
return this.model.count({
|
|
|
|
|
uid: uid
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-20 20:30:24 +08:00
|
|
|
|
module.exports = logModel;
|