@anglr/rest
Version:
Angular module representing rest services
34 lines • 1.62 kB
JavaScript
import { HttpEventType } from '@angular/common/http';
import { filter } from 'rxjs';
/**
* Middleware that is used for handling report progress setting, if not set returns only final http response with data
*/
export class ReportProgressMiddleware {
//######################### public static properties #########################
/**
* String identification of middleware
*/
static { this.id = 'ReportProgressMiddleware'; }
//######################### public methods - implementation of RestMiddleware #########################
/**
* Runs code that is defined for this rest middleware, in this method you can modify request and response
* @param this - Method is bound to RESTClient
* @param id - Unique id that identifies request method
* @param target - Prototype of class that are decorators applied to
* @param methodName - Name of method that is being modified
* @param descriptor - Descriptor of method that is being modified
* @param args - Array of arguments passed to called method
* @param request - Http request that you can modify
* @param next - Used for calling next middleware with modified request
*/
run(_id, _target, _methodName, descriptor, _args, request, next) {
if (descriptor.reportProgress) {
request = request.clone({
reportProgress: true
});
}
return next(request)
.pipe(filter(response => descriptor.reportProgress ? true : response.type == HttpEventType.Response));
}
}
//# sourceMappingURL=reportProgress.middleware.js.map