global-notification-setting.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const debug = require('debug')('growi:models:global-notification-setting');
  2. const mongoose = require('mongoose');
  3. const Notification = this;
  4. /*
  5. * define schema
  6. */
  7. const notificationSchema = new mongoose.Schema({
  8. isEnabled: { type: Boolean, required: true, default: true },
  9. triggerPath: { type: String, required: true },
  10. triggerEvents: { type: [String] },
  11. notifyTo: { type: String, default: '{}',
  12. get: data => {
  13. try {
  14. return JSON.parse(data);
  15. }
  16. catch (e) {
  17. return data;
  18. }
  19. },
  20. set: data => JSON.stringify(data)
  21. },
  22. });
  23. /**
  24. * GlobalNotificationSetting Class
  25. * @class GlobalNotificationSetting
  26. */
  27. class GlobalNotificationSetting {
  28. /**
  29. * enable notification setting
  30. * @param {string} id
  31. */
  32. static enable(id) {
  33. // return new Promise((resolve, reject) => {
  34. // save
  35. // return resolve(Notification)
  36. //}
  37. }
  38. /**
  39. * disable notification setting
  40. * @param {string} id
  41. */
  42. static disable(id) {
  43. // return new Promise((resolve, reject) => {
  44. // save
  45. // return resolve(Notification)
  46. //}
  47. }
  48. /**
  49. * find a list of notification settings by path and a list of events
  50. * @param {string} path
  51. * @param {string} event
  52. * @param {boolean} enabled
  53. */
  54. static findSettingByPathAndEvent(path, event, enabled) {
  55. // return new Promise((resolve, reject) => {
  56. // if(enabled == null) {
  57. // find all
  58. // }
  59. // else {
  60. // find only enabled/disabled
  61. // }
  62. // sort by path in mongoDB
  63. // return resolve([Notification])
  64. //}
  65. }
  66. }
  67. module.exports = function(crowi) {
  68. GlobalNotificationSetting.crowi = crowi;
  69. notificationSchema.loadClass(GlobalNotificationSetting);
  70. return mongoose.model('GlobalNotificationSetting', notificationSchema);
  71. };