Browse Source

Merge pull request #4201 from abpframework/feat/null-query-params

Add null query param control to RestService
pull/4209/head
Mehmet Erim 6 years ago
committed by GitHub
parent
commit
cc3aab78fc
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      npm/ng-packs/apps/dev-app/src/app/app.module.ts
  2. 1
      npm/ng-packs/packages/core/src/lib/models/common.ts
  3. 14
      npm/ng-packs/packages/core/src/lib/services/rest.service.ts

2
npm/ng-packs/apps/dev-app/src/app/app.module.ts

@ -23,6 +23,8 @@ const LOGGERS = [NgxsLoggerPluginModule.forRoot({ disabled: false })];
AppRoutingModule,
CoreModule.forRoot({
environment,
sendNullsAsQueryParam: false,
skipGetAppConfiguration: false,
}),
ThemeSharedModule.forRoot(),
AccountConfigModule.forRoot({ redirectUrl: '/' }),

1
npm/ng-packs/packages/core/src/lib/models/common.ts

@ -13,6 +13,7 @@ export namespace ABP {
*/
requirements?: Config.Requirements;
skipGetAppConfiguration?: boolean;
sendNullsAsQueryParam?: boolean;
}
export interface Test {

14
npm/ng-packs/packages/core/src/lib/services/rest.service.ts

@ -1,5 +1,5 @@
import { HttpClient, HttpRequest } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Injectable, Inject } from '@angular/core';
import { Store } from '@ngxs/store';
import { Observable, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
@ -7,12 +7,18 @@ import { RestOccurError } from '../actions/rest.actions';
import { Rest } from '../models/rest';
import { ConfigState } from '../states/config.state';
import { isUndefinedOrEmptyString } from '../utils/common-utils';
import { ABP } from '../models/common';
import { CORE_OPTIONS } from '../tokens/options.token';
@Injectable({
providedIn: 'root',
})
export class RestService {
constructor(private http: HttpClient, private store: Store) {}
constructor(
@Inject(CORE_OPTIONS) private options: ABP.Root,
private http: HttpClient,
private store: Store,
) {}
private getApiFromStore(apiName: string): string {
return this.store.selectSnapshot(ConfigState.getApiUrl(apiName));
@ -41,8 +47,10 @@ export class RestService {
params: Object.keys(params).reduce((acc, key) => {
const value = params[key];
if (!isUndefinedOrEmptyString(value)) acc[key] = value;
if (isUndefinedOrEmptyString(value)) return acc;
if (value === null && !this.options.sendNullsAsQueryParam) return acc;
acc[key] = value;
return acc;
}, {}),
}),

Loading…
Cancel
Save