|
@@ -7,11 +7,16 @@ class OrgbindService extends Service {
|
|
|
super(ctx);
|
|
|
this.model = this.ctx.model.Orgbind;
|
|
|
}
|
|
|
- async create({ source, target }) {
|
|
|
+ async create({ source, ids = [] }) {
|
|
|
assert(source, 'source不存在');
|
|
|
- assert(target, 'target不存在');
|
|
|
+ assert(ids, 'ids不存在');
|
|
|
try {
|
|
|
- const res = await this.model.create({ source, target });
|
|
|
+ const res = await Promise.all(
|
|
|
+ ids.filter(async e => {
|
|
|
+ const info = await this.model.findOne({ source, target: e });
|
|
|
+ if (!info) await this.model.create({ source, target: e });
|
|
|
+ })
|
|
|
+ );
|
|
|
return { errcode: 0, errmsg: 'ok', data: res };
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
@@ -26,11 +31,15 @@ class OrgbindService extends Service {
|
|
|
throw error;
|
|
|
}
|
|
|
}
|
|
|
- async delete({ id }) {
|
|
|
- assert(id, 'id不存在');
|
|
|
+ async delete({ source, ids = [] }) {
|
|
|
+ assert(ids, 'ids不存在');
|
|
|
try {
|
|
|
- await this.model.deleteOne({ _id: id });
|
|
|
- return { errcode: 0, errmsg: 'ok', data: '' };
|
|
|
+ const res = await Promise.all(
|
|
|
+ ids.filter(async e => {
|
|
|
+ await this.model.deleteOne({ source, target: e });
|
|
|
+ })
|
|
|
+ );
|
|
|
+ return { errcode: 0, errmsg: 'ok', data: res };
|
|
|
} catch (error) {
|
|
|
throw error;
|
|
|
}
|