lrf402788946 il y a 4 ans
Parent
commit
6dcd50d5e8
1 fichiers modifiés avec 23 ajouts et 0 suppressions
  1. 23 0
      app/service/achieve_apply_expert.js

+ 23 - 0
app/service/achieve_apply_expert.js

@@ -27,6 +27,29 @@ class Achieve_apply_expertService extends CrudService {
     const res = await this.model.count(query);
     return res;
   }
+
+  async create(data) {
+    const { apply_id, expert_id, type } = data;
+    console.log(expert_id);
+    let idata = [];
+    if (_.isArray(expert_id)) {
+      for (const e_id of expert_id) {
+        const obj = { apply_id, expert_id: e_id, type };
+        const res = await this.isInApply(obj);
+        if (res)idata.push(obj);
+      }
+      await this.model.insertMany(idata);
+    } else {
+      idata = { apply_id, expert_id, type };
+      const res = await this.isInApply(idata);
+      if (res) { await this.model.create(idata); }
+    }
+  }
+
+  async isInApply(data) {
+    const count = await this.model.count(data);
+    return count <= 0;
+  }
 }
 
 module.exports = Achieve_apply_expertService;