@@ -4,7 +4,7 @@ import { Actions, Effect, ofType } from '@ngrx/effects';
4
4
import { Action } from '@ngrx/store' ;
5
5
import { Observable , of } from 'rxjs' ;
6
6
import { ToastrService } from 'ngx-toastr' ;
7
- import { catchError , map , mergeMap } from 'rxjs/operators' ;
7
+ import { catchError , map , mergeMap , switchMap } from 'rxjs/operators' ;
8
8
import { EntryService } from '../services/entry.service' ;
9
9
import * as actions from './entry.actions' ;
10
10
@@ -13,6 +13,22 @@ export class EntryEffects {
13
13
constructor ( private actions$ : Actions , private entryService : EntryService , private toastrService : ToastrService ) {
14
14
}
15
15
16
+ @Effect ( )
17
+ switchEntryRunning$ : Observable < Action > = this . actions$ . pipe (
18
+ ofType ( actions . EntryActionTypes . SWITCH_TIME_ENTRY ) ,
19
+ switchMap ( ( action : actions . SwitchTimeEntry ) =>
20
+ this . entryService . stopEntryRunning ( action . idEntrySwitching ) . pipe (
21
+ map ( ( ) => {
22
+ return new actions . CreateEntry ( { project_id : action . idProjectSwitching , start_date : new Date ( ) . toISOString ( ) } ) ;
23
+ } ) ,
24
+ catchError ( ( error ) => {
25
+ this . toastrService . warning ( error . error . message ) ;
26
+ return of ( new actions . StopTimeEntryRunningFail ( error . error . message ) ) ;
27
+ } )
28
+ )
29
+ )
30
+ ) ;
31
+
16
32
@Effect ( )
17
33
loadEntriesSummary$ : Observable < Action > = this . actions$ . pipe (
18
34
ofType ( actions . EntryActionTypes . LOAD_ENTRIES_SUMMARY ) ,
@@ -46,7 +62,7 @@ export class EntryEffects {
46
62
} else {
47
63
const endDate = new Date ( activeEntry . start_date ) ;
48
64
endDate . setHours ( 23 , 59 , 59 ) ;
49
- return new actions . UpdateEntry ( { id : activeEntry . id , end_date : endDate . toISOString ( ) } ) ;
65
+ return new actions . UpdateEntry ( { id : activeEntry . id , end_date : endDate . toISOString ( ) } ) ;
50
66
}
51
67
}
52
68
} ) ,
0 commit comments