numFailed: number;
peerTypes: ComboboxEntry[];
peerRecord: number;
+ existingMaps: any;
onOpenSub: Subscription;
if (this.peerTypes.length === 0) {
this.getPeerTypes();
}
+
+ this.fetchExisting();
});
}
this.onOpenSub.unsubscribe();
}
+ fetchExisting() {
+ this.existingMaps = {};
+ this.pcrud.search('bpbcm',
+ {target_copy: this.copyIds, peer_record: this.peerRecord})
+ .subscribe(map => this.existingMaps[map.target_copy()] = map);
+ }
+
getPeerTypes(): Promise<any> {
return this.pcrud.retrieveAll('bpt', {}, {atomic: true}).toPromise()
.then(types =>
}
const id = this.ids.pop();
- const map = this.idl.create('bpbcm');
+ const map = this.existingMaps[id] || this.idl.create('bpbcm');
map.peer_record(this.peerRecord);
map.target_copy(id);
map.peer_type(this.peerType);
- return this.pcrud.create(map).toPromise().then(
+ let promise: Promise<any>;
+ if (this.existingMaps[id]) {
+ promise = this.pcrud.update(map).toPromise();
+ } else {
+ promise = this.pcrud.create(map).toPromise();
+ }
+
+ return promise.then(
ok => {
this.successMsg.current().then(msg => this.toast.success(msg));
this.numSucceeded++;