|
|
@@ -1,37 +1,38 @@
|
|
|
const debug = require('debug')('growi:models:global-notification-setting');
|
|
|
const mongoose = require('mongoose');
|
|
|
-const Notification = this;
|
|
|
+// const Notification = this;
|
|
|
|
|
|
/*
|
|
|
- * define schema
|
|
|
+ * parent schema
|
|
|
*/
|
|
|
-
|
|
|
-const notifyToSchema = new mongoose.Schema({
|
|
|
- type: { type: String, required: true },
|
|
|
- extended: {
|
|
|
- type: String,
|
|
|
- default: '{}',
|
|
|
- get: function(data) {
|
|
|
- try {
|
|
|
- return JSON.parse(data);
|
|
|
- }
|
|
|
- catch (e) {
|
|
|
- return data;
|
|
|
- }
|
|
|
- },
|
|
|
- set: function(data) {
|
|
|
- return JSON.stringify(data);
|
|
|
- }
|
|
|
- },
|
|
|
-});
|
|
|
-
|
|
|
const notificationSchema = new mongoose.Schema({
|
|
|
isEnabled: { type: Boolean, required: true, default: true },
|
|
|
triggerPath: { type: String, required: true },
|
|
|
triggerEvents: { type: [String] },
|
|
|
- notifyTo: notifyToSchema
|
|
|
});
|
|
|
|
|
|
+/*
|
|
|
+ * child schema inherited from notificationSchema
|
|
|
+ * stored in globalnotificationsettings collection
|
|
|
+ */
|
|
|
+const createChildSchemas = (parentSchema, className, modelName, discriminatorKey) => {
|
|
|
+ parentSchema.loadClass(className);
|
|
|
+ const Notification = mongoose.model(modelName, parentSchema);
|
|
|
+ const mailNotification = Notification.discriminator('mail', new mongoose.Schema({
|
|
|
+ toEmail: String,
|
|
|
+ }, {discriminatorKey: discriminatorKey}));
|
|
|
+
|
|
|
+ const slackNotification = Notification.discriminator('slack', new mongoose.Schema({
|
|
|
+ slackChannels: String,
|
|
|
+ }, {discriminatorKey: discriminatorKey}));
|
|
|
+
|
|
|
+ return {
|
|
|
+ Mail: mailNotification,
|
|
|
+ Slack: slackNotification,
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* GlobalNotificationSetting Class
|
|
|
* @class GlobalNotificationSetting
|
|
|
@@ -79,10 +80,19 @@ class GlobalNotificationSetting {
|
|
|
// return resolve([Notification])
|
|
|
//}
|
|
|
}
|
|
|
+
|
|
|
+ // DELETEME
|
|
|
+ test(s) {
|
|
|
+ console.log(s)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = function(crowi) {
|
|
|
GlobalNotificationSetting.crowi = crowi;
|
|
|
- notificationSchema.loadClass(GlobalNotificationSetting);
|
|
|
- return mongoose.model('GlobalNotificationSetting', notificationSchema);
|
|
|
+ return createChildSchemas(
|
|
|
+ notificationSchema,
|
|
|
+ GlobalNotificationSetting,
|
|
|
+ 'GlobalNotificationSetting',
|
|
|
+ 'type',
|
|
|
+ );
|
|
|
};
|