clean
This commit is contained in:
parent
52a0c188ac
commit
68a8bf1f06
@ -16,7 +16,7 @@ module.exports = function (config) {
|
|||||||
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
clearContext: false // leave Jasmine Spec Runner output visible in browser
|
||||||
},
|
},
|
||||||
coverageIstanbulReporter: {
|
coverageIstanbulReporter: {
|
||||||
dir: require('path').join(__dirname, '../../../coverage/poweredsoft/ngx-data'),
|
dir: require('path').join(__dirname, '../../../coverage/openharbor/ngx-data'),
|
||||||
reports: ['html', 'lcovonly', 'text-summary'],
|
reports: ['html', 'lcovonly', 'text-summary'],
|
||||||
fixWebpackSourcePaths: true
|
fixWebpackSourcePaths: true
|
||||||
},
|
},
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
|
||||||
"dest": "../../../dist/poweredsoft/ngx-data",
|
"dest": "../../../dist/openharbor/ngx-data",
|
||||||
"lib": {
|
"lib": {
|
||||||
"entryFile": "src/public-api.ts"
|
"entryFile": "src/public-api.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "@poweredsoft/ngx-data",
|
"name": "@openharbor/ngx-data",
|
||||||
"version": "0.0.22",
|
"version": "0.1.0",
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "^8.2.4",
|
"@angular/common": "^8.2.4",
|
||||||
"@angular/core": "^8.2.4",
|
"@angular/core": "^8.2.4",
|
||||||
"@poweredsoft/data": "^0.0.31",
|
"@poweredsoft/data": "^0.0.31",
|
||||||
"rxjs": "^6.5.3"
|
"rxjs": "^6.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,14 +1,13 @@
|
|||||||
import { HttpClient } from "@angular/common/http";
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from "@poweredsoft/data";
|
import { IQueryCriteria, IQueryExecutionGroupResult, IQueryExecutionResult, IQueryExecutionResultPaging } from '@poweredsoft/data';
|
||||||
import { Observable, of } from "rxjs";
|
import { Observable, of } from 'rxjs';
|
||||||
import { map, switchMap } from "rxjs/operators";
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { BaseHttpDataSourceOptionsBuilder } from "./BaseHttpDataSourceOptionsBuilder";
|
import { BaseHttpDataSourceOptionsBuilder } from './BaseHttpDataSourceOptionsBuilder';
|
||||||
|
|
||||||
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
||||||
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey>
|
extends BaseHttpDataSourceOptionsBuilder<TModel, TKey> {
|
||||||
{
|
|
||||||
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
private _beforeRead: (query: IQueryCriteria) => Observable<TQuery>;
|
||||||
|
|
||||||
constructor(http: HttpClient) {
|
constructor(http: HttpClient) {
|
||||||
super(http);
|
super(http);
|
||||||
}
|
}
|
||||||
@ -22,7 +21,7 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: IQueryCriteria) => {
|
handle: (query: IQueryCriteria) => {
|
||||||
const finalBeforeRead = this._beforeRead || ((query: IQueryCriteria) => of(<TQuery>{}));
|
const finalBeforeRead = this._beforeRead || ((query: IQueryCriteria) => of({} as TQuery));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
@ -30,24 +29,22 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
params: this.convertToParams(finalQuery)
|
params: this.convertToParams(finalQuery)
|
||||||
}).pipe(
|
}).pipe(
|
||||||
map(result => {
|
map(result => {
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
return {
|
||||||
{
|
|
||||||
totalRecords: result == null ? 0 : 1,
|
totalRecords: result == null ? 0 : 1,
|
||||||
data: [result]
|
data: [result]
|
||||||
};
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected convertToParams(finalQuery: TQuery)
|
protected convertToParams(finalQuery: TQuery) {
|
||||||
{
|
|
||||||
return Object.keys(finalQuery).reduce((prev, key) => {
|
return Object.keys(finalQuery).reduce((prev, key) => {
|
||||||
prev[key] = finalQuery[key];
|
prev[key] = finalQuery[key];
|
||||||
return prev;
|
return prev;
|
||||||
@ -58,24 +55,23 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
this._query = {
|
this._query = {
|
||||||
adapter: {
|
adapter: {
|
||||||
handle: (query: IQueryCriteria) => {
|
handle: (query: IQueryCriteria) => {
|
||||||
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of(<TQuery>{}));
|
const finalBeforeRead = this._beforeRead || ((_: IQueryCriteria) => of({} as TQuery));
|
||||||
return finalBeforeRead(query)
|
return finalBeforeRead(query)
|
||||||
.pipe(
|
.pipe(
|
||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
return this.http.post<TModel>(url, finalQuery).pipe(
|
return this.http.post<TModel>(url, finalQuery).pipe(
|
||||||
map(result => {
|
map(result => {
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>
|
return {
|
||||||
{
|
|
||||||
totalRecords: result == null ? 0 : 1,
|
totalRecords: result == null ? 0 : 1,
|
||||||
data: [result]
|
data: [result]
|
||||||
};
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -90,17 +86,17 @@ export class SingleDataSourceOptionsBuilder<TQuery, TModel, TKey>
|
|||||||
switchMap(finalQuery => {
|
switchMap(finalQuery => {
|
||||||
return queryHandler(finalQuery).pipe(
|
return queryHandler(finalQuery).pipe(
|
||||||
map(result => {
|
map(result => {
|
||||||
return <IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>>{
|
return {
|
||||||
totalRecords: result == null ? 0 : 1,
|
totalRecords: result == null ? 0 : 1,
|
||||||
data: [result]
|
data: [result]
|
||||||
};
|
} as IQueryExecutionResult<TModel> & IQueryExecutionGroupResult<TModel>;
|
||||||
})
|
})
|
||||||
)
|
);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
import { Injectable } from "@angular/core";
|
import { Injectable } from '@angular/core';
|
||||||
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||||
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent, IDataSourceError, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
import { IDataSourceTransportOptions, IDataSourceCommandAdapterOptions, IDataSourceOptions, IResolveCommandModelEvent, IDataSourceError, IDataSourceErrorMessage, IDataSourceValidationError } from '@poweredsoft/data';
|
||||||
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
|
import { IQueryExecutionResult, IQueryExecutionGroupResult, IQueryCriteria } from '@poweredsoft/data';
|
||||||
@ -9,7 +9,7 @@ import { throwError, Observable, of } from 'rxjs';
|
|||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class GenericRestDataSourceService
|
export class GenericRestDataSourceService
|
||||||
{
|
{
|
||||||
constructor(private http: HttpClient) {
|
constructor(private http: HttpClient) {
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export class GenericRestDataSourceService
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
private _handleErrorPipe(err: HttpErrorResponse) : Observable<IDataSourceError> {
|
||||||
|
|
||||||
if (err.status == 500) {
|
if (err.status == 500) {
|
||||||
return throwError(<IDataSourceErrorMessage>{
|
return throwError(<IDataSourceErrorMessage>{
|
||||||
type: 'message',
|
type: 'message',
|
||||||
@ -25,7 +25,7 @@ export class GenericRestDataSourceService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.status == 400)
|
if (err.status == 400)
|
||||||
{
|
{
|
||||||
if (err.error && err.error.errors)
|
if (err.error && err.error.errors)
|
||||||
return throwError(<IDataSourceValidationError>{
|
return throwError(<IDataSourceValidationError>{
|
||||||
@ -127,4 +127,4 @@ export class GenericRestDataSourceService
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user