before read in generic ds.
This commit is contained in:
parent
5fae118850
commit
99bcbf45ed
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@poweredsoft/ngx-data",
|
||||
"version": "0.0.18",
|
||||
"version": "0.0.19",
|
||||
"peerDependencies": {
|
||||
"@angular/common": "^8.2.4",
|
||||
"@angular/core": "^8.2.4",
|
||||
|
@ -3,8 +3,8 @@ import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent, IDataSourceError, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
||||
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
|
||||
import { IDataSourceQueryAdapterOptions } from '@poweredsoft/data';
|
||||
import { catchError} from 'rxjs/operators';
|
||||
import { throwError, Observable } from 'rxjs';
|
||||
import { catchError, switchMap} from 'rxjs/operators';
|
||||
import { throwError, Observable, of } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@ -56,9 +56,9 @@ export class GenericRestDataSourceService
|
||||
});
|
||||
}
|
||||
|
||||
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, manageNotificationMessage: boolean = true) : IDataSourceOptions<TModel>
|
||||
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceOptions<TModel>
|
||||
{
|
||||
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver);
|
||||
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver, beforeRead);
|
||||
|
||||
const dataSourceOptions: IDataSourceOptions<TModel> = {
|
||||
defaultCriteria: defaultCriteria,
|
||||
@ -73,13 +73,19 @@ export class GenericRestDataSourceService
|
||||
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
|
||||
}
|
||||
|
||||
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey) : IDataSourceTransportOptions<TModel> {
|
||||
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, beforeRead?: (query: IQueryCriteria) => Observable<IQueryCriteria>) : IDataSourceTransportOptions<TModel> {
|
||||
|
||||
const query: IDataSourceQueryAdapterOptions<TModel> = {
|
||||
adapter: {
|
||||
handle: (criteria: IQueryCriteria) => {
|
||||
const queryRoute = `${route}/read`;
|
||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, criteria);
|
||||
const finalBeforeRead = beforeRead || (t => of(criteria));
|
||||
return finalBeforeRead(criteria)
|
||||
.pipe(
|
||||
switchMap(finalQuery => {
|
||||
return this.http.post<IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>(queryRoute, finalQuery);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user