|
@@ -6,7 +6,7 @@ export class queryService {
|
|
|
private dataFromStorage: Subject<any> = new Subject()
|
|
|
private filteredResult: Subject<any> = new Subject()
|
|
|
|
|
|
- public query(storageAddress: Storage, ...conditions: Entries[]): Observable<any> {
|
|
|
+ public query(storageAddress: Storage, ...conditions: Conditions[]): Observable<any> {
|
|
|
this.loadObsData(storageAddress.address)
|
|
|
this.filterFromObs(...conditions)
|
|
|
return this.filteredResult.pipe()
|
|
@@ -29,14 +29,14 @@ export class queryService {
|
|
|
}
|
|
|
|
|
|
// Search and Filter: Pure Observables. To be moved out to become a separate service again.
|
|
|
- private filterFromObs(...conditions: Entries[]) {
|
|
|
+ private filterFromObs(...conditions: Conditions[]) {
|
|
|
this.dataFromStorage.subscribe({
|
|
|
next: element => {
|
|
|
// Logic to check if data meets the conditions, if so, put it into result.next{}
|
|
|
if (this.hasKeyAndValue(element, ...conditions)) {
|
|
|
this.filteredResult.next(element)
|
|
|
} else {
|
|
|
- console.log(`${element.header.messageID} does not match search criteria`)
|
|
|
+ // console.log(`${element.header.messageName} does not match search criteria`)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -75,7 +75,12 @@ export class queryService {
|
|
|
let objectValue = _.get(object, lodashPath);
|
|
|
let searchValue = searchObj[key];
|
|
|
|
|
|
- if (typeof searchValue === 'object' && typeof objectValue === 'object') {
|
|
|
+ if (Array.isArray(searchValue) && key === 'msgTag') {
|
|
|
+ // Check if any of the search values are included in the object value
|
|
|
+ return searchValue.some((value) => {
|
|
|
+ return Array.isArray(objectValue) ? objectValue.includes(value) : objectValue === value;
|
|
|
+ });
|
|
|
+ } else if (typeof searchValue === 'object' && typeof objectValue === 'object') {
|
|
|
return isMatchingObject(objectValue);
|
|
|
} else {
|
|
|
return objectValue === searchValue;
|
|
@@ -83,6 +88,8 @@ export class queryService {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+
|
|
|
let isObjectMatching = (object) => {
|
|
|
if (typeof object !== 'object') {
|
|
|
return false;
|
|
@@ -112,7 +119,7 @@ export class queryService {
|
|
|
|
|
|
|
|
|
// Entries that client will use. Subject to be improved later on
|
|
|
-export interface Entries {
|
|
|
+export interface Conditions {
|
|
|
_id?: string,
|
|
|
appLogLocId?: string,
|
|
|
msgId?: string,
|
|
@@ -120,7 +127,7 @@ export interface Entries {
|
|
|
msgDateTime?: Date | string,
|
|
|
msgTag?: string[],
|
|
|
msgPayload?: string,
|
|
|
- messageID: string
|
|
|
+ messageID?: string
|
|
|
}
|
|
|
|
|
|
export interface Storage {
|