@rolatech/angular-services 20.0.2-beta.3 → 20.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -5,7 +5,7 @@ import * as i1 from '@angular/material/button';
|
|
|
5
5
|
import { MatButtonModule } from '@angular/material/button';
|
|
6
6
|
import { switchMap, map, take, BehaviorSubject, Observable, Subject, firstValueFrom } from 'rxjs';
|
|
7
7
|
import _ from 'lodash';
|
|
8
|
-
import { HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
8
|
+
import { HttpClient, HttpParams, HTTP_INTERCEPTORS } from '@angular/common/http';
|
|
9
9
|
import { APP_CONFIG } from '@rolatech/angular-common';
|
|
10
10
|
import { Location, isPlatformBrowser } from '@angular/common';
|
|
11
11
|
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
|
|
@@ -126,11 +126,6 @@ class BaseService {
|
|
|
126
126
|
withCredentials: true,
|
|
127
127
|
});
|
|
128
128
|
}
|
|
129
|
-
search(word, withCredentials = true) {
|
|
130
|
-
return this.http.get(`${this.actionUrl}?search=${word}`, {
|
|
131
|
-
withCredentials,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
129
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: BaseService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
135
130
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: BaseService, providedIn: 'root' });
|
|
136
131
|
}
|
|
@@ -3009,9 +3004,43 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.2.0", ngImpor
|
|
|
3009
3004
|
|
|
3010
3005
|
class PropertySearchService extends BaseService {
|
|
3011
3006
|
init() {
|
|
3012
|
-
this.endpoint = 'properties
|
|
3007
|
+
this.endpoint = 'properties';
|
|
3013
3008
|
super.init();
|
|
3014
3009
|
}
|
|
3010
|
+
search1(options) {
|
|
3011
|
+
return this.http.get(`${this.actionUrl}/search`, {
|
|
3012
|
+
params: options,
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
search(rawParams) {
|
|
3016
|
+
const params = this.stripUndefined(rawParams);
|
|
3017
|
+
// Decide route: empty filter → DB list; else → Elasticsearch-backed search
|
|
3018
|
+
const isEmpty = this.isEmptyFilter(params);
|
|
3019
|
+
let httpParams = new HttpParams();
|
|
3020
|
+
for (const [k, v] of Object.entries(params)) {
|
|
3021
|
+
if (Array.isArray(v)) {
|
|
3022
|
+
v.forEach((item) => (httpParams = httpParams.append(k, String(item))));
|
|
3023
|
+
}
|
|
3024
|
+
else {
|
|
3025
|
+
httpParams = httpParams.set(k, String(v));
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
return isEmpty
|
|
3029
|
+
? this.http.get(`${this.actionUrl}`, { params: httpParams }) // DB list
|
|
3030
|
+
: this.http.get(`${this.actionUrl}/search`, { params: httpParams }); // ES search
|
|
3031
|
+
}
|
|
3032
|
+
stripUndefined(obj) {
|
|
3033
|
+
const out = {};
|
|
3034
|
+
for (const [k, v] of Object.entries(obj)) {
|
|
3035
|
+
if (v !== undefined && v !== null && !(Array.isArray(v) && v.length === 0) && v !== '') {
|
|
3036
|
+
out[k] = v;
|
|
3037
|
+
}
|
|
3038
|
+
}
|
|
3039
|
+
return out;
|
|
3040
|
+
}
|
|
3041
|
+
isEmptyFilter(params, ignoreKeys = ['page', 'limit', 'sort']) {
|
|
3042
|
+
return Object.entries(params).every(([k, v]) => ignoreKeys.includes(k) || v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0));
|
|
3043
|
+
}
|
|
3015
3044
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: PropertySearchService, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
3016
3045
|
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.2.0", ngImport: i0, type: PropertySearchService, providedIn: 'root' });
|
|
3017
3046
|
}
|