11import { Injectable , Injector } from '@angular/core' ;
22
33import { Actions , createEffect , ofType } from '@ngrx/effects' ;
4- import { catchError , filter , map , mergeMap , take } from 'rxjs/operators' ;
4+ import { catchError , filter , map , mergeMap , take , withLatestFrom } from 'rxjs/operators' ;
55
66import { hasValue , isNotEmpty } from '../../shared/empty.util' ;
77import { StoreActionTypes } from '../../store.actions' ;
88import { getClassForType } from '../cache/builders/build-decorators' ;
99import { RawRestResponse } from '../dspace-rest/raw-rest-response.model' ;
1010import { DspaceRestService } from '../dspace-rest/dspace-rest.service' ;
1111import { DSpaceSerializer } from '../dspace-rest/dspace.serializer' ;
12- // import { XSRFService } from '../xsrf/xsrf.service';
12+ import { XSRFService } from '../xsrf/xsrf.service' ;
1313import {
1414 RequestActionTypes ,
1515 RequestErrorAction ,
@@ -22,25 +22,25 @@ import { ParsedResponse } from '../cache/response.models';
2222import { RequestError } from './request-error.model' ;
2323import { RestRequestWithResponseParser } from './rest-request-with-response-parser.model' ;
2424import { RequestEntry } from './request-entry.model' ;
25+ import { RestRequestMethod } from './rest-request-method' ;
2526
2627@Injectable ( )
2728export class RequestEffects {
2829
29- execute = createEffect ( ( ) => this . actions$ . pipe (
30+ execute = createEffect ( ( ) => this . actions$ . pipe (
3031 ofType ( RequestActionTypes . EXECUTE ) ,
3132 mergeMap ( ( action : RequestExecuteAction ) => {
3233 return this . requestService . getByUUID ( action . payload ) . pipe (
3334 take ( 1 )
3435 ) ;
3536 } ) ,
3637 filter ( ( entry : RequestEntry ) => hasValue ( entry ) ) ,
37- map ( ( entry : RequestEntry ) => entry . request ) ,
38- //TODO: test once rest part is aligned
39- //withLatestFrom(this.xsrfService.tokenInitialized$),
38+ // TODO: test once rest part is aligned
39+ withLatestFrom ( this . xsrfService . tokenInitialized$ ) ,
4040 // If it's a GET request, or we have an XSRF token, dispatch it immediately
4141 // Otherwise wait for the XSRF token first
42- // filter(([entry, tokenInitialized]: [RequestEntry, boolean] ) => entry.request.method === RestRequestMethod.GET || tokenInitialized === true),
43- // map(([entry, tokenInitialized]: [RequestEntry, boolean ]) => entry.request),
42+ filter ( ( [ entry , tokenInitialized ] ) => entry ? .request ? .method === RestRequestMethod . GET || tokenInitialized === true ) ,
43+ map ( ( [ entry , ] ) => entry . request ) ,
4444 mergeMap ( ( request : RestRequestWithResponseParser ) => {
4545 let body = request . body ;
4646 if ( isNotEmpty ( request . body ) && ! request . isMultipart ) {
@@ -81,7 +81,7 @@ export class RequestEffects {
8181 private restApi : DspaceRestService ,
8282 private injector : Injector ,
8383 protected requestService : RequestService ,
84- // protected xsrfService: XSRFService,
84+ protected xsrfService : XSRFService ,
8585 ) { }
8686
8787}
0 commit comments