yapi/server/models/follow.js

74 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-08-10 12:13:32 +08:00
import baseModel from './base.js';
class followModel extends baseModel {
getName() {
return 'follow';
}
getSchema() {
return {
uid: { type: Number, required: true },
projectid: { type: Number, required: true },
projectname: { type: String, required: true },
2017-08-11 17:49:47 +08:00
icon: String,
color: String
2017-08-10 12:13:32 +08:00
};
}
/**
* @param {Number} uid 用户id
* @param {Number} projectid 项目id
* @param {String} projectname 项目名
* @param {String} icon 项目图标
*/
save(data) {//关注
let saveData = {
uid: data.uid,
projectid: data.projectid,
projectname: data.projectname,
2017-08-11 17:49:47 +08:00
icon: data.icon,
color: data.color
2017-08-10 12:13:32 +08:00
};
let follow = new this.model(saveData);
return follow.save();
}
del(id){
return this.model.deleteOne({
_id: id
});
}
listWithPaging(uid, page, limit) {
page = parseInt(page);
limit = parseInt(limit);
return this.model.find({
uid: uid
}).skip((page - 1) * limit).limit(limit).exec();
}
listCount(uid) {
return this.model.count({
uid: uid
});
}
checkProjectRepeat(uid,projectid){
return this.model.count({
uid: uid,
projectid: projectid
});
}
2017-08-14 15:17:05 +08:00
2017-08-22 11:23:00 +08:00
updateById(id,typeid,data){
2017-08-14 15:17:05 +08:00
return this.model.update({
2017-08-22 11:23:00 +08:00
uid: id,
projectid: typeid
},data,{runValidators: true });
2017-08-14 15:17:05 +08:00
}
2017-08-10 12:13:32 +08:00
}
module.exports = followModel;