Commit ca02c0f5 authored by tobinski's avatar tobinski
Browse files

Change response collection from the url topic

parent 457cb0dd
......@@ -165,7 +165,7 @@ export class ApiController {
// flag to check if we already answered
let answered = false;
const responseData = new ResponseCollector(req.config, language);
const responseData = new ResponseCollector(req.config);
// if kafka is not answering give a fuck
const kafkaTimeout = setTimeout(() => {
// check if we already answered
......
import {InterfaceStreamAppResponse} from '../controller/api';
import UrlResolver from './url-resolver';
/**
......@@ -29,49 +28,23 @@ export class ResponseCollector {
*/
private config: string[];
/**
* Language oif the provider
*/
private language: string;
/**
* The config is a simple array with the names of the kafka streming apps
* @param config
* @param language
*/
constructor(config: string[], language = 'de') {
constructor(config: string[]) {
this.config = config;
this.language = language;
}
/**
* Add a data to the final result
* @param {InterfaceStreamAppResponse} data
*/
async add(data: InterfaceStreamAppResponse): Promise<void> {
add(data: InterfaceStreamAppResponse): void {
// should always be the same
this.finalData.id = data.id;
// find key and add data
console.log('config ' + this.config);
console.log('name' + data.name);
if(this.config.indexOf(data.name) > -1){
// check if array
if(Array.isArray(data.data.links)) {
console.log('links');
data.data.links = await Promise.all(data.data.links.map(async (d) => {
const a = {};
try {
const provider = await UrlResolver.getProvider(d, this.language);
a[provider] = d;
return a;
} catch(error) {
console.log(`error getting provider` + error);
a['unknown'] = d;
return a;
}
}));
console.log(data.data.links);
}
if(Array.isArray(this.finalData.data[data.name])) {
this.finalData.data[data.name].push(data.data);
} else {
......@@ -113,6 +86,3 @@ export class ResponseCollector {
return this.finalData;
}
}
export class InterfaceResponseConfig {
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment