|
@@ -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;
|