global-notification-setting.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. */
  15. notificationSchema.statics.create = () => {
  16. // save
  17. // return Notification
  18. };
  19. /**
  20. * enable notification setting
  21. * @param {string} id
  22. */
  23. notificationSchema.statics.enable = id => {
  24. // save
  25. // return Notification
  26. };
  27. /**
  28. * disable notification setting
  29. * @param {string} id
  30. */
  31. notificationSchema.statics.disable = id => {
  32. // save
  33. // return Notification
  34. };
  35. /**
  36. * delete notification setting
  37. * @param {string} id
  38. */
  39. notificationSchema.statics.delete = id => {
  40. // delete notification setting
  41. // remove
  42. // return;
  43. };
  44. /**
  45. * update notification setting
  46. * @param {string} id
  47. */
  48. notificationSchema.statics.update = id => {
  49. // save
  50. // return Notification
  51. };
  52. /**
  53. * find a notification setting by id
  54. * @param {string} id
  55. */
  56. notificationSchema.statics.findSettingById = id => {
  57. // findOne
  58. // return Notification
  59. };
  60. /**
  61. * find a list of notification settings by path and a list of events
  62. * @param {string} path
  63. * @param {string} event
  64. */
  65. notificationSchema.statics.findSettingByPathAndEvent = (path, event) => {
  66. // find
  67. // return [Notification]
  68. };
  69. // classify a list of notification settings into enabled and disabled
  70. notificationSchema.mothods.classify = settings => {
  71. // return {enabled: [Notification], disabled: [Notification]}
  72. };
  73. // returns only enabled notification settings
  74. notificationSchema.mothods.getEnabeldSettings = settings => {
  75. // return [Notification]
  76. };
  77. // sort a list of notifications by path from short to long
  78. notificationSchema.mothods.sortByPath = settings => {
  79. // return [Notification]
  80. };
  81. return mongoose.model('GlobalNotificationSetting', notificationSchema);
  82. };
  83. // const notifications = await findSettingByPathAndEvent(path, event);
  84. // notifications.forEach(notification => {
  85. // notification.send(); //??????????
  86. // });