api scaffold
This commit is contained in:
parent
ddcc767573
commit
96d74a7732
6 changed files with 128 additions and 60 deletions
30
src/api/APIManager.ts
Normal file
30
src/api/APIManager.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue