GlobalNotificationSlackSetting.js 1.0 KB

1234567891011121314151617181920212223242526
  1. const mongoose = require('mongoose');
  2. const notificationSchema = require('./GlobalNotificationSettingParentSchema');
  3. const GlobalNotificationSettingClass = require('./GlobalNotificationSettingClass');
  4. /**
  5. * create child schemas inherited from parentSchema
  6. * all child schemas are stored in globalnotificationsettings collection
  7. * @link{http://url.com module_name}
  8. * @param {object} parentSchema
  9. * @param {string} modelName
  10. * @param {string} discriminatorKey
  11. */
  12. const createChildSchemas = (parentSchema, modelName, discriminatorKey) => {
  13. const Notification = mongoose.model(modelName, parentSchema);
  14. const slackNotification = Notification.discriminator('slack', new mongoose.Schema({
  15. slackChannels: String,
  16. }, {discriminatorKey: discriminatorKey}));
  17. return slackNotification;
  18. };
  19. module.exports = function(crowi) {
  20. GlobalNotificationSettingClass.crowi = crowi;
  21. notificationSchema.loadClass(GlobalNotificationSettingClass);
  22. return createChildSchemas(notificationSchema, 'GlobalNotificationSetting', 'type');
  23. };