global-notification-setting.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. module.exports = function(crowi) {
  2. const debug = require('debug')('growi:models:global-notification-setting');
  3. const mongoose = require('mongoose');
  4. const Notification = this;
  5. let notificationSchema;
  6. notificationSchema = new mongoose.Schema({
  7. isEnabled: { type: Boolean, required: true, default: false },
  8. triggerPath: { type: String, required: true },
  9. triggerEvents: { type: [String] },
  10. toEmail: { type: String, required: true },
  11. });
  12. /**
  13. * create new notification setting
  14. * @param {string} triggerPath
  15. * @param {[string]} triggerEvents
  16. * @param {string} toEmail
  17. */
  18. notificationSchema.statics.create = (triggerPath, triggerEvents, toEmail) => {
  19. // return new Promise((resolve, reject) => {
  20. // save
  21. // return resolve(Notification)
  22. //}
  23. };
  24. /**
  25. * enable notification setting
  26. * @param {string} id
  27. */
  28. notificationSchema.statics.enable = id => {
  29. // return new Promise((resolve, reject) => {
  30. // save
  31. // return resolve(Notification)
  32. //}
  33. };
  34. /**
  35. * disable notification setting
  36. * @param {string} id
  37. */
  38. notificationSchema.statics.disable = id => {
  39. // return new Promise((resolve, reject) => {
  40. // save
  41. // return resolve(Notification)
  42. //}
  43. };
  44. /**
  45. * delete notification setting
  46. * @param {string} id
  47. */
  48. notificationSchema.statics.delete = id => {
  49. // return new Promise((resolve, reject) => {
  50. // remove
  51. // return resolve()
  52. //}
  53. };
  54. /**
  55. * update notification setting
  56. * @param {string} id
  57. */
  58. notificationSchema.statics.update = id => {
  59. // return new Promise((resolve, reject) => {
  60. // save
  61. // return resolve(Notification)
  62. //}
  63. };
  64. /**
  65. * find a notification setting by id
  66. * @param {string} id
  67. */
  68. notificationSchema.statics.findSettingById = id => {
  69. // return new Promise((resolve, reject) => {
  70. // findOne
  71. // return resolve(Notification)
  72. //}
  73. };
  74. /**
  75. * find a list of notification settings by path and a list of events
  76. * @param {string} path
  77. * @param {string} event
  78. */
  79. notificationSchema.statics.findSettingByPathAndEvent = (path, event) => {
  80. // return new Promise((resolve, reject) => {
  81. // find
  82. // return resolve([Notification])
  83. //}
  84. };
  85. // classify a list of notification settings into enabled and disabled
  86. notificationSchema.methods.classify = settings => {
  87. // return resolve({enabled: [Notification], disabled: [Notification]})
  88. };
  89. // returns only enabled notification settings
  90. notificationSchema.methods.getEnabeldSettings = settings => {
  91. // return resolve([Notification])
  92. };
  93. // sort a list of notifications by path from short to long
  94. notificationSchema.methods.sortByPath = settings => {
  95. // return resolve([Notification])
  96. };
  97. return mongoose.model('GlobalNotificationSetting', notificationSchema);
  98. };