editor-settings.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {
  2. Schema, Model, Document,
  3. } from 'mongoose';
  4. import { getOrCreateModel } from '@growi/core';
  5. export interface ILintRule {
  6. name: string;
  7. options?: unknown;
  8. isEnabled?: boolean;
  9. }
  10. export interface ITextlintSettings {
  11. isTexlintEnabled: string;
  12. textlintRules: ILintRule[];
  13. }
  14. export interface IEditorSettings {
  15. userId: Schema.Types.ObjectId;
  16. textlintSettings: ITextlintSettings;
  17. }
  18. export interface EditorSettingsDocument extends IEditorSettings, Document {}
  19. export type EditorSettingsModel = Model<EditorSettingsDocument>
  20. const textlintSettingsSchema = new Schema<ITextlintSettings>({
  21. isTextlintEnabled: { type: Boolean, default: false },
  22. textlintRules: {
  23. type: [
  24. { name: { type: String }, options: { type: Object }, isEnabled: { type: Boolean } },
  25. ],
  26. },
  27. });
  28. const editorSettingsSchema = new Schema<EditorSettingsDocument, EditorSettingsModel>({
  29. userId: { type: String },
  30. textlintSettings: textlintSettingsSchema,
  31. });
  32. export default getOrCreateModel<EditorSettingsDocument, EditorSettingsModel>('EditorSettings', editorSettingsSchema);