yapi/server/models/follow.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

const baseModel = require('./base.js');
2017-08-10 12:13:32 +08:00
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();
}
2017-08-22 17:00:27 +08:00
del(projectid, uid){
2017-08-10 12:13:32 +08:00
return this.model.deleteOne({
2017-08-22 17:00:27 +08:00
projectid: projectid,
uid: uid
2017-08-10 12:13:32 +08:00
});
}
2017-08-22 17:00:27 +08:00
list(uid) {
2017-08-10 12:13:32 +08:00
return this.model.find({
uid: uid
2017-08-22 17:00:27 +08:00
}).exec();
2017-08-10 12:13:32 +08:00
}
listByProjectId(projectid){
return this.model.find({
projectid: projectid
})
}
2017-08-10 12:13:32 +08:00
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;