| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- const debug = require('debug')('growi:models:global-notification-setting');
- const mongoose = require('mongoose');
- const Notification = this;
- /*
- * define schema
- */
- const notificationSchema = new mongoose.Schema({
- isEnabled: { type: Boolean, required: true, default: true },
- triggerPath: { type: String, required: true },
- triggerEvents: { type: [String] },
- notifyTo: { type: String, default: '{}',
- get: data => {
- try {
- return JSON.parse(data);
- }
- catch (e) {
- return data;
- }
- },
- set: data => JSON.stringify(data)
- },
- });
- /**
- * GlobalNotificationSetting Class
- * @class GlobalNotificationSetting
- */
- class GlobalNotificationSetting {
- /**
- * enable notification setting
- * @param {string} id
- */
- static enable(id) {
- // return new Promise((resolve, reject) => {
- // save
- // return resolve(Notification)
- //}
- }
- /**
- * disable notification setting
- * @param {string} id
- */
- static disable(id) {
- // return new Promise((resolve, reject) => {
- // save
- // return resolve(Notification)
- //}
- }
- /**
- * find a list of notification settings by path and a list of events
- * @param {string} path
- * @param {string} event
- * @param {boolean} enabled
- */
- static findSettingByPathAndEvent(path, event, enabled) {
- // return new Promise((resolve, reject) => {
- // if(enabled == null) {
- // find all
- // }
- // else {
- // find only enabled/disabled
- // }
- // sort by path in mongoDB
- // return resolve([Notification])
- //}
- }
- }
- module.exports = function(crowi) {
- GlobalNotificationSetting.crowi = crowi;
- notificationSchema.loadClass(GlobalNotificationSetting);
- return mongoose.model('GlobalNotificationSetting', notificationSchema);
- };
|