mock平台

syncModel.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const yapi = require('yapi.js');
  2. const baseModel = require('models/base.js');
  3. const mongoose = require('mongoose');
  4. class syncModel extends baseModel {
  5. getName() {
  6. return 'interface_auto_sync';
  7. }
  8. getSchema() {
  9. return {
  10. uid: { type: Number},
  11. project_id: { type: Number, required: true },
  12. //是否开启自动同步
  13. is_sync_open: { type: Boolean, default: false },
  14. //自动同步定时任务的cron表达式
  15. sync_cron: String,
  16. //自动同步获取json的url
  17. sync_json_url: String,
  18. //接口合并模式 good,nomarl等等 意思也就是智能合并,完全覆盖等
  19. sync_mode: String,
  20. //上次成功同步接口时间,
  21. last_sync_time: Number,
  22. //上次同步的swagger 文档内容
  23. old_swagger_content: String,
  24. add_time: Number,
  25. up_time: Number,
  26. };
  27. }
  28. getByProjectId(id) {
  29. return this.model.findOne({
  30. project_id: id
  31. })
  32. }
  33. delByProjectId(project_id){
  34. return this.model.remove({
  35. project_id: project_id
  36. })
  37. }
  38. save(data) {
  39. data.up_time = yapi.commons.time();
  40. let m = new this.model(data);
  41. return m.save();
  42. }
  43. listAll() {
  44. return this.model
  45. .find({})
  46. .select(
  47. '_id uid project_id add_time up_time is_sync_open sync_cron sync_json_url sync_mode old_swagger_content last_sync_time'
  48. )
  49. .sort({ _id: -1 })
  50. .exec();
  51. }
  52. up(data) {
  53. let id = data.id;
  54. delete data.id;
  55. data.up_time = yapi.commons.time();
  56. return this.model.update({
  57. _id: id
  58. }, data)
  59. }
  60. upById(id, data) {
  61. delete data.id;
  62. data.up_time = yapi.commons.time();
  63. return this.model.update({
  64. _id: id
  65. }, data)
  66. }
  67. del(id){
  68. return this.model.remove({
  69. _id: id
  70. })
  71. }
  72. delByProjectId(projectId){
  73. return this.model.remove({
  74. project_id: projectId
  75. })
  76. }
  77. }
  78. module.exports = syncModel;