Browse Source

feat(core): add null query param control to request method of rest service

#4129
pull/4201/head
mehmet-erim 6 years ago
parent
commit
1d49072345
  1. 2
      npm/ng-packs/apps/dev-app/src/app/app.module.ts
  2. 17
      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, AppRoutingModule,
CoreModule.forRoot({ CoreModule.forRoot({
environment, environment,
sendNullsAsQueryParam: false,
skipGetAppConfiguration: false,
}), }),
ThemeSharedModule.forRoot(), ThemeSharedModule.forRoot(),
AccountConfigModule.forRoot({ redirectUrl: '/' }), AccountConfigModule.forRoot({ redirectUrl: '/' }),

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

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

Loading…
Cancel
Save