liuyu 4 rokov pred
rodič
commit
c390c22ff5
2 zmenil súbory, kde vykonal 22 pridanie a 0 odobranie
  1. 4 0
      app/controller/lookuser.js
  2. 18 0
      app/service/lookuser.js

+ 4 - 0
app/controller/lookuser.js

@@ -13,6 +13,10 @@ class LookuserController extends Controller {
     this.service = this.ctx.service.lookuser;
   }
 
+  async index() {
+    const data = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...data });
+  }
 }
 
 module.exports = CrudController(LookuserController, meta);

+ 18 - 0
app/service/lookuser.js

@@ -11,6 +11,7 @@ class LookuserService extends CrudService {
   constructor(ctx) {
     super(ctx, 'lookuser');
     this.model = this.ctx.model.Lookuser;
+    this.rmodel = this.ctx.model.Roomuser;
   }
 
   async create(data) {
@@ -21,6 +22,23 @@ class LookuserService extends CrudService {
     }
   }
 
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const lookuser = await this.model
+      .find(info)
+      .skip(Number(skip))
+      .limit(Number(limit));
+    const data = [];
+    for (const _lookuser of lookuser) {
+      const lu = JSON.parse(JSON.stringify(_lookuser));
+      const ruser = await this.rmodel.findById(_lookuser.userid);
+      const _ruser = JSON.parse(JSON.stringify(ruser));
+      const newdata = { ...lu, ..._ruser };
+      data.push(newdata);
+    }
+    return { data, total };
+  }
+
 
 }