api scaffold

This commit is contained in:
mProjectsCode 2022-05-04 19:09:54 +02:00
parent ddcc767573
commit 96d74a7732
6 changed files with 128 additions and 60 deletions

30
src/api/APIManager.ts Normal file
View file

@ -0,0 +1,30 @@
import {APIModel} from './APIModel';
import {APIRequestResult} from './APIRequestResult';
export class APIManager {
apis: APIModel[];
constructor() {
this.apis = [];
}
async query(query: string, types: string[] = []): Promise<APIRequestResult[]> {
console.log('MDB | api manager queried');
let res: APIRequestResult[] = [];
for (const api of this.apis) {
if (types.length === 0 || api.hasTypeOverlap(types)) {
const apiRes = await api.getByTitle(query);
// console.log(apiRes);
res = res.concat(apiRes);
}
}
return res;
}
registerAPI(api: APIModel): void {
this.apis.push(api);
}
}