guhongwei 4 years ago
parent
commit
e400ca892a
5 changed files with 118 additions and 1 deletions
  1. 56 0
      app/controller/.zhwldriver.js
  2. 16 0
      app/controller/zhwldriver.js
  3. 25 0
      app/model/zhwldriver.js
  4. 5 1
      app/router.js
  5. 16 0
      app/service/zhwldriver.js

+ 56 - 0
app/controller/.zhwldriver.js

@@ -0,0 +1,56 @@
+module.exports = {
+  create: {
+    requestBody: [
+      "!name",
+      "!tel",
+      "!id_card",
+      "!drive_card",
+      "fhc_time",
+      "car_type",
+      "ccu_time",
+      "cc_time",
+      "qc_time",
+    ],
+  },
+  destroy: {
+    params: ["!id"],
+    service: "delete",
+  },
+  update: {
+    params: ["!id"],
+    requestBody: [
+      "!name",
+      "!tel",
+      "!id_card",
+      "!drive_card",
+      "fhc_time",
+      "car_type",
+      "ccu_time",
+      "cc_time",
+      "qc_time",
+    ],
+  },
+  show: {
+    parameters: {
+      params: ["!id"],
+    },
+    service: "fetch",
+  },
+  index: {
+    parameters: {
+      query: {
+        name: "name",
+        tel: "tel",
+        id_card: "id_card",
+        drive_card: "drive_card",
+      },
+    },
+    service: "query",
+    options: {
+      query: ["skip", "limit"],
+      sort: ["meta.createdAt"],
+      desc: true,
+      count: true,
+    },
+  },
+};

+ 16 - 0
app/controller/zhwldriver.js

@@ -0,0 +1,16 @@
+'use strict';
+
+// const _ = require('lodash');
+const meta = require('./.zhwldriver.js');
+const Controller = require('egg').Controller;
+const { CrudController } = require('naf-framework-mongoose/lib/controller');
+
+// 司机表
+class ZhwldriverController extends Controller {
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.zhwldriver;
+  }
+}
+
+module.exports = CrudController(ZhwldriverController, meta);

+ 25 - 0
app/model/zhwldriver.js

@@ -0,0 +1,25 @@
+'use strict';
+const Schema = require('mongoose').Schema;
+const metaPlugin = require('naf-framework-mongoose/lib/model/meta-plugin');
+// 司机表
+const Zhwldriverchema = {
+  name: { type: String, required: true, maxLength: 200 }, // 姓名
+  tel: { type: String, required: true, maxLength: 200 }, // 电话/固定电话
+  id_card: { type: Number, required: true, maxLength: 200 }, // 身份证
+  drive_card: { type: String, required: true, maxLength: 200 }, // 驾驶证号
+  fhc_time: { type: String, required: false, maxLength: 200 }, // 初次领证时间=年月日
+  car_type: { type: String, required: false, maxLength: 200 }, // 准驾车型
+  ccu_time: { type: String, required: false, maxLength: 200 }, // 驾驶证有效日期
+  cc_time: { type: String, required: false, maxLength: 200 }, // 驾驶证年检日期
+  qc_time: { type: String, required: false, maxLength: 200 }, // 资格证年检日期
+};
+
+
+const schema = new Schema(Zhwldriverchema, { toJSON: { virtuals: true } });
+schema.index({ id: 1 });
+schema.plugin(metaPlugin);
+
+module.exports = app => {
+  const { mongoose } = app;
+  return mongoose.model('Zhwldriver', schema, 'zhwldriver');
+};

+ 5 - 1
app/router.js

@@ -12,11 +12,15 @@ module.exports = app => {
   // 用户表
   router.resources('user', '/api/servicezhwl/user', controller.user); // index、create、show、destroy
   router.post('user', '/api/servicezhwl/user/update/:id', controller.user.update);
-
   // 用户登录
   router.post('/api/servicezhwl/login', controller.login.login);
   // 根据token取得用户信息
   router.post('/api/servicezhwl/token', controller.login.token);
   // 用户退出登录
   router.post('/api/servicezhwl/logout', controller.login.destroy);
+
+  // 司机表
+  router.resources('zhwldriver', '/api/servicezhwl/zhwldriver', controller.zhwldriver); // index、create、show、destroy
+  router.post('zhwldriver', '/api/servicezhwl/zhwldriver/update/:id', controller.zhwldriver.update);
+
 };

+ 16 - 0
app/service/zhwldriver.js

@@ -0,0 +1,16 @@
+'use strict';
+
+const assert = require('assert');
+const _ = require('lodash');
+const { ObjectId } = require('mongoose').Types;
+const { CrudService } = require('naf-framework-mongoose/lib/service');
+const { ZhwldriverError, ErrorCode } = require('naf-core').Error;
+
+class ZhwldriverService extends CrudService {
+  constructor(ctx) {
+    super(ctx, 'zhwldriver');
+    this.model = this.ctx.model.Zhwldriver;
+  }
+}
+
+module.exports = ZhwldriverService;