浏览代码

minor fix

Enzo 1 年之前
父节点
当前提交
f1c54bf6f6
共有 6 个文件被更改,包括 39 次插入43 次删除
  1. 3 9
      services/dataprep.service.ts
  2. 4 25
      services/query.service.ts
  3. 2 2
      test/test1.ts
  4. 2 3
      test/test2.ts
  5. 3 4
      test/test4.ts
  6. 25 0
      types/interface.ts

+ 3 - 9
services/dataprep.service.ts

@@ -1,7 +1,7 @@
 import mongoose, { Model, Mongoose } from "mongoose";
 import { Observable, Subject } from "rxjs";
 import * as fs from 'fs'
-import { Storage, StorageLocation } from "./query.service";
+import { StorageLocation } from "../types/interface";
 
 
 export class DataPrepService {
@@ -10,17 +10,11 @@ export class DataPrepService {
     private connectionStatus = 0
 
     // Data preparations: Purely Observables
-    public loadObsData(storage: Storage, dataFromStorage: Subject<any>) {
+    public loadObsData(storage: StorageLocation, dataFromStorage: Subject<any>) {
         if (storage.type == `File`) {
             this.streamFileData(storage, dataFromStorage)
         } else {
-            if (storage.type != `observable`)
-            {
-                this.streamMongoData(storage as StorageLocation, dataFromStorage)
-            }
-            else{
-                //....
-            }
+            this.streamMongoData(storage, dataFromStorage)
         }
     }
 

+ 4 - 25
services/query.service.ts

@@ -2,6 +2,7 @@ import { isObject, get } from 'lodash'
 import { Observable, Subject, interval, map, of } from 'rxjs'
 import { DataPrepService } from './dataprep.service'
 import _ = require("lodash")
+import { Conditions, DateRange, Storage } from '../types/interface'
 export class SearchService {
 
     private dataPrepService: DataPrepService
@@ -22,8 +23,8 @@ export class SearchService {
     public query(storage: Storage, ...conditions: Conditions[]): Observable<any> {
         let dataFromStorage: Subject<any> = new Subject()
         let filteredResult: Subject<any> = new Subject()
-        // check if storaage is of type ObservableStorage
-        if (typeof storage === "object" && storage !== null && "type" in storage && "ref" in storage) {
+
+        if (storage.type == 'observable') {
             let obsRef = storage.ref
             obsRef.subscribe((element) => {
                 dataFromStorage.next(element)
@@ -31,6 +32,7 @@ export class SearchService {
         } else {
             this.dataPrepService.loadObsData(storage, dataFromStorage)
         }
+
         this.filterFromObs(dataFromStorage, filteredResult, ...conditions)
         return filteredResult.pipe()
     }
@@ -172,26 +174,3 @@ export class SearchService {
 
 }
 
-
-
-// Entries that client will use. Subject to be improved later on
-export interface Conditions {
-    $regex?: string,
-    $dateRange?: DateRange,
-    [key: string]: string | Date | DateRange | string[]
-}
-export interface DateRange {
-    startDate: string | Date,
-    endDate: string | Date,
-    column: string
-}
-export interface StorageLocation {
-    type: string,
-    url: string
-}
-export interface ObservableStorage {
-    type: "observable",
-    ref: Observable<any>
-}
-
-export type Storage = ObservableStorage | StorageLocation

+ 2 - 2
test/test1.ts

@@ -4,14 +4,14 @@ data to be filtered
  */
 import { Observable } from "rxjs"
 import { SearchService } from "../services/query.service"
-import { Conditions, Storage } from "../services/query.service"
 import {  isObject } from 'lodash'
 import _ = require("lodash")
+import { Conditions, StorageLocation } from "../types/interface"
 
 let query = new SearchService()
 
 //For now just local file storage. More will be preapred in the design phase later.
-let storageAddress: Storage = {
+let storageAddress: StorageLocation = {
     type: "File",
     url: "payload.json"
 }

+ 2 - 3
test/test2.ts

@@ -4,13 +4,12 @@ data to be filtered
  */
 import { Observable } from "rxjs"
 import { SearchService } from "../services/query.service"
-import { Conditions, Storage } from "../services/query.service"
-import { isObject } from 'lodash'
 import _ = require("lodash")
+import { Conditions, StorageLocation } from "../types/interface"
 
 let query = new SearchService()
 
-let mongoStorage : Storage = {
+let mongoStorage : StorageLocation = {
     type: `MongoDB`,
     url: `mongodb://192.168.100.59:27017/default`
 }

+ 3 - 4
test/test4.ts

@@ -1,16 +1,16 @@
 /* 
  */
 import { Observable, Subject, of } from "rxjs"
-import { ObservableStorage, SearchService } from "../services/query.service"
-import { Conditions, Storage } from "../services/query.service"
+import { SearchService } from "../services/query.service"
 import _ = require("lodash")
 import { DataPrepService } from "../services/dataprep.service"
+import { Conditions, ObservableStorage, StorageLocation } from "../types/interface"
 
 let query = new SearchService()
 let dataPrepService = new DataPrepService()
 
 
-let mongoStorage: Storage = {
+let mongoStorage: StorageLocation = {
     type: `MongoDB`,
     url: `mongodb://192.168.100.59:27017/default`
 }
@@ -103,7 +103,6 @@ let conditions8: Conditions[] = [
 let obsStorage : Subject<any> = new Subject()
 dataPrepService.loadObsData(mongoStorage, obsStorage)
 
-
 const testObs: ObservableStorage = {
     type: "observable",
     ref: obsStorage

+ 25 - 0
types/interface.ts

@@ -0,0 +1,25 @@
+import { Observable } from "rxjs"
+
+export interface Conditions {
+    $regex?: string,
+    $dateRange?: DateRange,
+    [key: string]: string | Date | DateRange | string[]
+}
+export interface DateRange {
+    startDate: string | Date,
+    endDate: string | Date,
+    column: string
+}
+
+export type StorageLocationType = 'File' | 'MongoDB'
+
+export interface StorageLocation {
+    type: StorageLocationType,
+    url: string
+}
+export interface ObservableStorage {
+    type: "observable",
+    ref: Observable<any>
+}
+
+export type Storage = ObservableStorage | StorageLocation