-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
airtable.ts
56 lines (49 loc) · 1.49 KB
/
airtable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import Airtable, {Base} from 'airtable';
export interface Maintainer {
name: string,
socials: {
github?: string,
email?: string
}
profile_pic: string
}
export interface Project {
id: string,
name: string,
project_link: string,
maintainer: Maintainer
}
export class AirtableAdapter{
private readonly base: Base;
constructor(api_key: string, base_id: string){
this.base = new Airtable({apiKey: api_key}).base(base_id);
}
async projects(){
const projects: Array<Project> = [];
const records = await this.base('Projects').select({
view: 'Grid view'
}).all();
for (const record of records) {
const maintainer: Maintainer = await this.getMaintainer(record.get('Maintainers')[0]);
projects.push({
id: record.getId(),
name: record.get('Name') as string,
project_link: record.get('Project Link') as string,
maintainer
});
}
return projects;
}
private async getMaintainer(id: string): Promise<Maintainer>{
const _ = await this.base('Maintainers').find(id);
const maintainer: Maintainer = {
name: _.get('Name') as string,
socials: {
email: _.get('Email') as string,
github: _.get('Github') as string
},
profile_pic: _.get('Profile Picture')[0].url
}
return maintainer
}
}