Steven Fukase 4 лет назад
Родитель
Сommit
b9cefb1a71

+ 0 - 19
packages/app/src/server/models/editor-settings.js

@@ -1,19 +0,0 @@
-module.exports = function(crowi) {
-  const mongoose = require('mongoose');
-  const editorSettingsSchema = new mongoose.Schema({
-    userId: { type: String },
-    isTextlintEnabled: { type: Boolean, default: true },
-    commonTextlintRules: {
-      type: [
-        { name: { type: String }, options: { type: Object }, isEnabled: { type: Boolean } },
-      ],
-    },
-    japaneseTextlintRules: {
-      type: [
-        { name: { type: String }, options: { type: Object }, isEnabled: { type: Boolean } },
-      ],
-    },
-  });
-
-  return mongoose.model('EditorSettings', editorSettingsSchema);
-};

+ 41 - 0
packages/app/src/server/models/editor-settings.ts

@@ -0,0 +1,41 @@
+import {
+  Schema, Model, Document,
+} from 'mongoose';
+import { getOrCreateModel } from '../util/mongoose-utils';
+
+
+export interface ILintRule {
+  name: string;
+  options?: unknown;
+  isEnabled?: boolean;
+}
+
+export interface ITextlintSettings {
+  isTexlintEnabled: string;
+  textlintRules: ILintRule[];
+}
+
+export interface IEditorSettings {
+  userId: Schema.Types.ObjectId;
+  textlintSettings: ITextlintSettings;
+}
+
+export interface EditorSettingsDocument extends IEditorSettings, Document {}
+export type EditorSettingsModel = Model<EditorSettingsDocument>
+
+const textlintSettingsSchema = new Schema<ITextlintSettings>({
+  isTextlintEnabled: { type: Boolean, default: true },
+  textlintRules: {
+    type: [
+      { name: { type: String }, options: { type: Object }, isEnabled: { type: Boolean } },
+    ],
+  },
+});
+
+const editorSettingsSchema = new Schema<IEditorSettings>({
+  userId: { type: String },
+  textlintSettings: textlintSettingsSchema,
+});
+
+
+export default getOrCreateModel<EditorSettingsDocument, EditorSettingsModel>('EditorSettings', editorSettingsSchema);

+ 0 - 1
packages/app/src/server/models/index.js

@@ -17,5 +17,4 @@ module.exports = {
   GlobalNotificationSlackSetting: require('./GlobalNotificationSetting/GlobalNotificationSlackSetting'),
   ShareLink: require('./share-link'),
   SlackAppIntegration: require('./slack-app-integration'),
-  EditorSettings: require('./editor-settings'),
 };