From 5e964dd8e859e611cce64f6fb60b766b35f26c0a Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Sun, 30 Jul 2017 16:38:28 +0200 Subject: [PATCH] Simplify save function. --- src/operations/operationList.component.ts | 28 +++++++++-------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/operations/operationList.component.ts b/src/operations/operationList.component.ts index 9b5a5ac..dd68568 100644 --- a/src/operations/operationList.component.ts +++ b/src/operations/operationList.component.ts @@ -125,25 +125,19 @@ export class OperationListComponent implements OnInit { save(operation) { operation.confirmed = true; - var observable: Observable; + 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) {