lrf 2 years ago
parent
commit
f5aea5868c
4 changed files with 27 additions and 19 deletions
  1. 5 9
      package.json
  2. 1 10
      src/configuration.ts
  3. 14 0
      src/entity/meta.js
  4. 7 0
      src/entity/modelBase.ts

+ 5 - 9
package.json

@@ -19,14 +19,6 @@
     "index.d.ts"
   ],
   "license": "MIT",
-  "dependencies": {
-    "@midwayjs/swagger": "^3.7.1",
-    "swagger-ui-dist": "^4.15.2",
-    "@midwayjs/typegoose": "^3.0.0",
-    "@typegoose/typegoose": "^9.0.0",
-    "lodash": "^4.17.21",
-    "mongoose": "^6.0.7"
-  },
   "devDependencies": {
     "@midwayjs/cli": "^2.0.0",
     "@midwayjs/core": "^3.0.0",
@@ -40,6 +32,10 @@
     "mwts": "^1.0.5",
     "ts-jest": "^29.0.3",
     "typescript": "~4.8.0",
-    "@types/lodash": "^4.14.190"
+    "@types/lodash": "^4.14.190",
+    "@midwayjs/typegoose": "^3.0.0",
+    "@typegoose/typegoose": "^9.0.0",
+    "lodash": "^4.17.21",
+    "mongoose": "^6.0.7"
   }
 }

+ 1 - 10
src/configuration.ts

@@ -1,8 +1,6 @@
 import { App, Configuration } from '@midwayjs/decorator';
 import * as DefaultConfig from './config/config.default';
 import * as koa from '@midwayjs/koa';
-// api文档
-import * as swagger from '@midwayjs/swagger';
 // 数据库
 import * as typegoose from '@midwayjs/typegoose';
 import * as Typegoose from '@typegoose/typegoose';
@@ -10,14 +8,7 @@ import { ResponseMiddleware } from './middleware/response.middleware';
 import { IMidwayApplication, IMidwayContainer } from '@midwayjs/core';
 @Configuration({
   namespace: 'free',
-  imports: [
-    koa,
-    typegoose,
-    {
-      component: swagger,
-      enabledEnvironment: ['local'],
-    },
-  ],
+  imports: [koa, typegoose],
   importConfigs: [
     {
       default: DefaultConfig,

+ 14 - 0
src/entity/meta.js

@@ -0,0 +1,14 @@
+'use strict';
+
+module.exports = exports = function metaPlugin(schema /* , options*/) {
+  schema.add({
+    meta: {
+      state: { type: Number, default: 0 }, // 数据状态: 0-正常;1-标记删除
+      comment: String,
+    },
+  });
+  schema.set('timestamps', {
+    createdAt: 'meta.createdAt',
+    updatedAt: 'meta.updatedAt',
+  });
+};

+ 7 - 0
src/entity/modelBase.ts

@@ -0,0 +1,7 @@
+import { modelOptions, plugin, Severity } from '@typegoose/typegoose';
+import * as meta from './meta';
+@modelOptions({
+  options: { allowMixed: Severity.ALLOW },
+})
+@plugin(meta)
+export class ModelBase {}