GlobalNotificationMailSetting.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { Model } from 'mongoose';
  2. import mongoose from 'mongoose';
  3. import type Crowi from '~/server/crowi';
  4. import { GlobalNotificationSettingType } from '../GlobalNotificationSetting';
  5. import {
  6. class as GlobalNotificationSettingClass,
  7. type GlobalNotificationSettingModel,
  8. schema as GlobalNotificationSettingSchema,
  9. type IGlobalNotificationSetting,
  10. } from './index';
  11. export interface IGlobalNotificationMailSetting
  12. extends IGlobalNotificationSetting {
  13. toEmail: string;
  14. }
  15. export type GlobalNotificationMailSettingModel =
  16. Model<IGlobalNotificationMailSetting> & GlobalNotificationSettingModel;
  17. const factory = (crowi: Crowi): GlobalNotificationMailSettingModel => {
  18. GlobalNotificationSettingClass.crowi = crowi;
  19. GlobalNotificationSettingSchema.loadClass(GlobalNotificationSettingClass);
  20. const GlobalNotificationSettingModel = mongoose.model<
  21. IGlobalNotificationSetting,
  22. GlobalNotificationSettingModel
  23. >('GlobalNotificationSetting', GlobalNotificationSettingSchema);
  24. const GlobalNotificationMailSettingModel =
  25. GlobalNotificationSettingModel.discriminator<
  26. IGlobalNotificationMailSetting,
  27. GlobalNotificationMailSettingModel
  28. >(
  29. GlobalNotificationSettingType.MAIL,
  30. new mongoose.Schema(
  31. {
  32. toEmail: String,
  33. },
  34. {
  35. discriminatorKey: 'type',
  36. },
  37. ),
  38. );
  39. return GlobalNotificationMailSettingModel;
  40. };
  41. export default factory;