Simplify save function.

This commit is contained in:
Alexis Lahouze 2017-07-30 16:38:28 +02:00
parent 25fcc34b68
commit 5e964dd8e8
1 changed files with 11 additions and 17 deletions

View File

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