reloaded %!s(int64=4) %!d(string=hai) anos
pai
achega
4fc785798b
Modificáronse 2 ficheiros con 19 adicións e 0 borrados
  1. 5 0
      app/controller/uploadtask.js
  2. 14 0
      app/service/uploadtask.js

+ 5 - 0
app/controller/uploadtask.js

@@ -13,6 +13,11 @@ class UploadtaskController extends Controller {
     this.service = this.ctx.service.uploadtask;
   }
 
+  async index() {
+    const res = await this.service.query(this.ctx.query);
+    this.ctx.ok({ ...res });
+  }
+
 
 }
 

+ 14 - 0
app/service/uploadtask.js

@@ -11,6 +11,20 @@ class UploadtaskService extends CrudService {
   constructor(ctx) {
     super(ctx, 'uploadtask');
     this.model = this.ctx.model.Uploadtask;
+    this.stumodel = this.ctx.model.Student;
+  }
+
+  async query({ skip, limit, ...info }) {
+    const total = await this.model.count(info);
+    const res = await this.model.find(info).skip(Number(skip)).limit(Number(limit));
+    const data = [];
+    for (const elm of res) {
+      const _elm = _.cloneDeep(JSON.parse(JSON.stringify(elm)));
+      const stu = await this.stumodel.findById(_elm.studentid);
+      _elm.stuname = stu.name;
+      data.push(_elm);
+    }
+    return { data, total };
   }
 
 }