lrf402788946 4 lat temu
rodzic
commit
d8efc2715f
3 zmienionych plików z 29 dodań i 0 usunięć
  1. 15 0
      app/controller/util.js
  2. 2 0
      app/router.js
  3. 12 0
      app/service/util.js

+ 15 - 0
app/controller/util.js

@@ -0,0 +1,15 @@
+'use strict';
+const Controller = require('egg').Controller;
+class UtilController extends Controller {
+
+  constructor(ctx) {
+    super(ctx);
+    this.service = this.ctx.service.util;
+  }
+
+  async utilMethod() {
+    const res = await this.service.utilMethod(this.ctx.query, this.ctx.request.body);
+    this.ctx.ok({ res });
+  }
+}
+module.exports = UtilController;

+ 2 - 0
app/router.js

@@ -632,4 +632,6 @@ module.exports = app => {
   );
   // 证书检验
   router.get('/api/train/cerconfirm', controller.cerconfirm.index);
+  // 工具方法
+  router.post('/api/train/util', controller.util.utilMethod);
 };

+ 12 - 0
app/service/util.js

@@ -72,6 +72,18 @@ class UtilService extends CrudService {
     const data = this.ctx.model[_model].prototype.schema.obj;
     return data;
   }
+  async utilMethod(data, body) {
+    console.log(data, body);
+    // const res = await this.ctx.model.Student.updateMany({ ...data, classid: { $exists: true } }, { classid: null });
+    const { code, ids, bedroomid } = body;
+    for (const id of ids) {
+      const r = await this.ctx.model.Student.findById(id);
+      r.bedroom = code;
+      r.bedroomid = bedroomid;
+      await r.save();
+      // await this.ctx.model.Student.findByIdAndUpdate(id, { bedroom: code, bedroomid });
+    }
+  }
 }
 
 module.exports = UtilService;