|
| 1 | +import { castToPromise } from './utilities'; |
1 | 2 | import { FilterConditions } from './../filter-conditions'; |
2 | 3 | import { FilterTemplates } from './../filter-templates'; |
3 | 4 | import { |
@@ -53,22 +54,23 @@ export class FilterService { |
53 | 54 | if (!serviceOptions || !serviceOptions.onBackendEventApi || !serviceOptions.onBackendEventApi.process || !serviceOptions.onBackendEventApi.service) { |
54 | 55 | throw new Error(`onBackendEventApi requires at least a "process" function and a "service" defined`); |
55 | 56 | } |
56 | | - const backendApi = serviceOptions.onBackendEventApi; |
57 | 57 |
|
58 | 58 | // run a preProcess callback if defined |
59 | | - if (backendApi.preProcess !== undefined) { |
60 | | - backendApi.preProcess(); |
| 59 | + if (serviceOptions.onBackendEventApi.preProcess) { |
| 60 | + serviceOptions.onBackendEventApi.preProcess(); |
61 | 61 | } |
62 | 62 |
|
63 | 63 | // call the service to get a query back |
64 | | - const query = await backendApi.service.onFilterChanged(event, args); |
| 64 | + const query = await serviceOptions.onBackendEventApi.service.onFilterChanged(event, args); |
65 | 65 |
|
66 | | - // await for the Promise to resolve the data |
67 | | - const responseProcess = await backendApi.process(query); |
| 66 | + // the process could be an Observable (like HttpClient) or a Promise |
| 67 | + // in any case, we need to have a Promise so that we can await on it (if an Observable, convert it to Promise) |
| 68 | + const observableOrPromise = serviceOptions.onBackendEventApi.process(query); |
| 69 | + const responseProcess = await castToPromise(observableOrPromise); |
68 | 70 |
|
69 | 71 | // send the response process to the postProcess callback |
70 | | - if (backendApi.postProcess !== undefined) { |
71 | | - backendApi.postProcess(responseProcess); |
| 72 | + if (serviceOptions.onBackendEventApi.postProcess !== undefined) { |
| 73 | + serviceOptions.onBackendEventApi.postProcess(responseProcess); |
72 | 74 | } |
73 | 75 | } |
74 | 76 |
|
|
0 commit comments