mock平台

follow.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. const baseModel = require('./base.js');
  2. class followModel extends baseModel {
  3. getName() {
  4. return 'follow';
  5. }
  6. getSchema() {
  7. return {
  8. uid: { type: Number, required: true },
  9. projectid: { type: Number, required: true },
  10. projectname: { type: String, required: true },
  11. icon: String,
  12. color: String
  13. };
  14. }
  15. /**
  16. * @param {Number} uid 用户id
  17. * @param {Number} projectid 项目id
  18. * @param {String} projectname 项目名
  19. * @param {String} icon 项目图标
  20. */
  21. save(data) {
  22. //关注
  23. let saveData = {
  24. uid: data.uid,
  25. projectid: data.projectid,
  26. projectname: data.projectname,
  27. icon: data.icon,
  28. color: data.color
  29. };
  30. let follow = new this.model(saveData);
  31. return follow.save();
  32. }
  33. del(projectid, uid) {
  34. return this.model.remove({
  35. projectid: projectid,
  36. uid: uid
  37. });
  38. }
  39. list(uid) {
  40. return this.model
  41. .find({
  42. uid: uid
  43. })
  44. .exec();
  45. }
  46. listByProjectId(projectid) {
  47. return this.model.find({
  48. projectid: projectid
  49. });
  50. }
  51. checkProjectRepeat(uid, projectid) {
  52. return this.model.countDocuments({
  53. uid: uid,
  54. projectid: projectid
  55. });
  56. }
  57. updateById(id, typeid, data) {
  58. return this.model.update(
  59. {
  60. uid: id,
  61. projectid: typeid
  62. },
  63. data,
  64. { runValidators: true }
  65. );
  66. }
  67. }
  68. module.exports = followModel;