Simplify save function.

This commit is contained in:
Alexis Lahouze 2017-07-30 16:38:28 +02:00
parent 25fcc34b68
commit 5e964dd8e8

View File

@ -125,25 +125,19 @@ export class OperationListComponent implements OnInit {
save(operation) { save(operation) {
operation.confirmed = true; operation.confirmed = true;
var observable: Observable<Operation>; return this.operationService.create(operation).subscribe(
(operation) => {
this.toastrService.success('Operation #' + operation.id + ' saved.');
if(operation.id){ this.load(this.minDate, this.maxDate);
observable = this.operationService.update(operation);
} else {
observable = this.operationService.create(operation);
}
return observable.subscribe((operation) => { return operation;
this.toastrService.success('Operation #' + operation.id + ' saved.'); }, (result) => {
this.toastrService.error(
this.load(this.minDate, this.maxDate); 'Error while saving operation: ' + result.message
);
return operation; }
}, (result) => { );
this.toastrService.error(
'Error while saving operation: ' + result.message
);
});
}; };
onUpdate(dateRange) { onUpdate(dateRange) {