advancing well the new helpers

This commit is contained in:
Mathias Beaulieu-Duncan 2019-09-13 11:53:25 -05:00
parent c89cc92d33
commit 3de4294ef5
4 changed files with 75 additions and 38 deletions

69
package-lock.json generated
View File

@ -418,12 +418,14 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -444,7 +446,8 @@
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"console-control-strings": {
"version": "1.1.0",
@ -595,6 +598,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -602,12 +606,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -626,6 +632,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -719,6 +726,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -1917,9 +1925,9 @@
}
},
"@poweredsoft/data": {
"version": "0.0.14",
"resolved": "https://registry.npmjs.org/@poweredsoft/data/-/data-0.0.14.tgz",
"integrity": "sha512-FKCFKUp4kdGO3BAiOT4hP3QOXDwH2hAtMrE41JecN9tsYckXXXYarUhVMOcU8Z8mz8KgK9lTcIZFwniBkbuFHQ==",
"version": "0.0.25",
"resolved": "https://registry.npmjs.org/@poweredsoft/data/-/data-0.0.25.tgz",
"integrity": "sha512-PUab9Q5+0eHTuxQvEyVh+iv3fwdq0lzJXq6SeS9kDIlBDYfFvvn7qiS5KTBZq+JqE+2RnlXF79agYutl4jRviA==",
"requires": {
"tslib": "^1.9.0"
}
@ -7143,7 +7151,8 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"concat-map": {
"version": "0.0.1",
@ -7154,7 +7163,8 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"core-util-is": {
"version": "1.0.2",
@ -7271,7 +7281,8 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"ini": {
"version": "1.3.5",
@ -7283,6 +7294,7 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -7305,12 +7317,14 @@
"minimist": {
"version": "0.0.8",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"minipass": {
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -7329,6 +7343,7 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -7409,7 +7424,8 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true
"dev": true,
"optional": true
},
"object-assign": {
"version": "4.1.1",
@ -7421,6 +7437,7 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -7542,6 +7559,7 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -12377,8 +12395,7 @@
"ansi-regex": {
"version": "2.1.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"aproba": {
"version": "1.2.0",
@ -12421,8 +12438,7 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
@ -12433,8 +12449,7 @@
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -12551,8 +12566,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -12564,7 +12578,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -12594,7 +12607,6 @@
"version": "2.3.5",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"safe-buffer": "^5.1.2",
"yallist": "^3.0.0"
@ -12613,7 +12625,6 @@
"version": "0.5.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"minimist": "0.0.8"
}
@ -12707,7 +12718,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -12793,8 +12803,7 @@
"safe-buffer": {
"version": "5.1.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"safer-buffer": {
"version": "2.1.2",
@ -12830,7 +12839,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -12850,7 +12858,6 @@
"version": "3.0.1",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"ansi-regex": "^2.0.0"
}
@ -12894,14 +12901,12 @@
"wrappy": {
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"yallist": {
"version": "3.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
}
}
},
@ -13227,6 +13232,7 @@
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -13395,6 +13401,7 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}

View File

@ -19,7 +19,7 @@
"@angular/platform-browser": "~8.2.4",
"@angular/platform-browser-dynamic": "~8.2.4",
"@angular/router": "~8.2.4",
"@poweredsoft/data": "0.0.14",
"@poweredsoft/data": "0.0.25",
"rxjs": "~6.5.3",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"

View File

@ -4,7 +4,7 @@
"peerDependencies": {
"@angular/common": "^8.2.4",
"@angular/core": "^8.2.4",
"@poweredsoft/data": "^0.0.14",
"@poweredsoft/data": "^0.0.25",
"rxjs": "^6.5.3"
}
}

View File

@ -1,8 +1,10 @@
import { Injectable } from "@angular/core";
import { HttpClient } from '@angular/common/http';
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions } from '@poweredsoft/data';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent } 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';
@Injectable({
providedIn: 'root'
@ -14,6 +16,34 @@ export class GenericRestDataSourceService
}
private _handleErrorPipe(err: HttpErrorResponse) : Observable<any> {
// is it a validation error
// is it something I can display nicely with a message
// unexpected message...
return throwError({
});
}
createDataSourceOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey, defaultCriteria: IQueryCriteria, manageNotificationMessage: boolean = true) : IDataSourceOptions<TModel>
{
const dataSourceTransportOptions = this.createStandardRestTransportOptions<TModel, TKey>(route, keyResolver);
const dataSourceOptions: IDataSourceOptions<TModel> = {
defaultCriteria: defaultCriteria,
resolveIdField: keyResolver,
manageNotificationMessage: manageNotificationMessage,
transport: dataSourceTransportOptions
};
return dataSourceOptions;
}
setResolveCommand<TModel>(options: IDataSourceOptions<TModel>, name: string, resolveCommandModel: (event: IResolveCommandModelEvent<TModel>) => Observable<any>) {
options.transport.commands[name].resolveCommandModel = resolveCommandModel;
}
createStandardRestTransportOptions<TModel, TKey>(route: string, keyResolver: (model: TModel) => TKey) : IDataSourceTransportOptions<TModel> {
const query: IDataSourceQueryAdapterOptions<TModel> = {
@ -28,7 +58,7 @@ export class GenericRestDataSourceService
const createCommand: IDataSourceCommandAdapterOptions<TModel> = {
adapter: {
handle: (command: TModel) => {
return this.http.post<TModel>(route, command);
return this.http.post<TModel>(route, command).pipe(catchError(this._handleErrorPipe));
}
}
};
@ -38,7 +68,7 @@ export class GenericRestDataSourceService
handle: (command: TModel) => {
const key = keyResolver(command);
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
return this.http.put<TModel>(updateRoute, command);
return this.http.put<TModel>(updateRoute, command).pipe(catchError(this._handleErrorPipe));
}
}
};
@ -48,7 +78,7 @@ export class GenericRestDataSourceService
handle: (command: TModel) => {
const key = keyResolver(command);
const updateRoute = `${route}/${encodeURIComponent(key as any)}`;
return this.http.delete<TModel>(updateRoute);
return this.http.delete<TModel>(updateRoute).pipe(catchError(this._handleErrorPipe));
}
}
};