reloaded 5 rokov pred
rodič
commit
83e95a888d
2 zmenil súbory, kde vykonal 20 pridanie a 1 odobranie
  1. 4 1
      app/controller/staff.js
  2. 16 0
      app/service/staff.js

+ 4 - 1
app/controller/staff.js

@@ -7,12 +7,15 @@ const { CrudController } = require('naf-framework-mongoose/lib/controller');
 
 // 人员表管理
 class StaffController extends Controller {
-
   constructor(ctx) {
     super(ctx);
     this.service = this.ctx.service.staff;
   }
 
+  async index() {
+    const res = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
 }
 
 module.exports = CrudController(StaffController, meta);

+ 16 - 0
app/service/staff.js

@@ -68,6 +68,22 @@ class StaffService extends CrudService {
     await this.umodel.findOneAndDelete({ userid: id });
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await (await this.model.find(info)).length;
+    const staffs = await this.model
+      .find(info)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    const newdata = [];
+    for (let staff of staffs) {
+      staff = JSON.parse(JSON.stringify(staff));
+      const user = await this.umodel.findOne({ userid: staff.id });
+      staff.type = user.type;
+      newdata.push(staff);
+    }
+    return { data: newdata, total };
+  }
+
   async fetch({ id }) {
     let staff = await this.model.findById(id);
     staff = JSON.parse(JSON.stringify(staff));