-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathHackathon.ts
More file actions
187 lines (154 loc) · 4.67 KB
/
Hackathon.ts
File metadata and controls
187 lines (154 loc) · 4.67 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Hackathon data types and mock data generator
import {
BiDataQueryOptions,
BiDataTable,
normalizeText,
TableCellRelation,
TableCellText,
TableCellUser,
TableCellValue,
TableRecord,
} from 'mobx-lark';
import { LarkBase, larkClient } from './Base';
export type Agenda = LarkBase &
Record<'summary' | 'name' | 'type' | 'startedAt' | 'endedAt', TableCellValue>;
export class AgendaModel extends BiDataTable<Agenda>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({ fields: { summary, ...fields }, ...meta }: TableRecord<Agenda>) {
return {
...meta,
...fields,
summary: (summary as TableCellText[])!.map(normalizeText),
};
}
}
export type Person = LarkBase &
Record<
| 'name'
| 'avatar'
| 'gender'
| 'age'
| 'address'
| 'organizations'
| 'skills'
| 'githubLink'
| 'githubAccount'
| 'createdBy',
TableCellValue
>;
export class PersonModel extends BiDataTable<Person>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({ fields: { githubLink, ...fields }, ...meta }: TableRecord<Person>) {
return {
...meta,
...fields,
githubLink: normalizeText(githubLink as TableCellText),
};
}
}
export type Organization = LarkBase &
Record<'name' | 'logo' | 'link' | 'members' | 'prizes', TableCellValue>;
export class OrganizationModel extends BiDataTable<Organization>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({ fields: { link, ...fields }, ...meta }: TableRecord<Organization>) {
return {
...meta,
...fields,
link: normalizeText(link as TableCellText),
};
}
}
export type Prize = LarkBase &
Record<
| 'summary'
| 'name'
| 'image'
| 'price'
| 'amount'
| 'level'
| `${'start' | 'end'}Rank`
| 'sponsor',
TableCellValue
>;
export class PrizeModel extends BiDataTable<Prize>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
}
export type Template = LarkBase &
Record<
'name' | 'languages' | 'tags' | 'summary' | `${'source' | 'preview'}Link` | 'products',
TableCellValue
>;
export class TemplateModel extends BiDataTable<Template>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({
fields: { languages, tags, sourceLink, previewLink, ...fields },
...meta
}: TableRecord<Template>) {
return {
...meta,
...fields,
languages: languages?.toString().split(/\s*,\s*/) || [],
tags: tags?.toString().split(/\s*,\s*/) || [],
sourceLink: normalizeText(sourceLink as TableCellText),
previewLink: normalizeText(previewLink as TableCellText),
};
}
}
export type Project = LarkBase &
Record<
'name' | 'summary' | 'group' | 'members' | 'products' | 'score' | 'rank' | 'prize',
TableCellValue
>;
export class ProjectModel extends BiDataTable<Project>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({ fields: { members, products, ...fields }, ...meta }: TableRecord<Project>) {
return {
...meta,
...fields,
members: (members as TableCellRelation[])?.map(normalizeText),
products: (products as TableCellRelation[])?.map(normalizeText),
};
}
}
export type Member = LarkBase &
Record<'summary' | 'person' | 'skills' | 'githubAccount' | 'project' | 'status', TableCellValue>;
export class MemberModel extends BiDataTable<Member>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({
fields: { summary, person, skills, githubAccount, ...fields },
...meta
}: TableRecord<Member>) {
return {
...meta,
...fields,
person: (person as TableCellUser[])?.[0],
summary: (summary as TableCellText[])!.map(normalizeText),
skills: skills?.toString().split(/\s*,\s*/) || [],
githubAccount: normalizeText(githubAccount as TableCellText),
};
}
}
export type Product = LarkBase &
Record<
'name' | 'project' | 'template' | 'link' | 'sourceLink' | 'file' | 'summary',
TableCellValue
>;
export class ProductModel extends BiDataTable<Product>() {
client = larkClient;
queryOptions: BiDataQueryOptions = { text_field_as_array: false };
extractFields({ fields: { link, sourceLink, ...fields }, ...meta }: TableRecord<Product>) {
return {
...meta,
...fields,
link: normalizeText(link as TableCellText),
sourceLink: normalizeText(sourceLink as TableCellText),
};
}
}