forked from FlatFilers/platform-sdk-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullExample.ts
81 lines (77 loc) · 1.87 KB
/
FullExample.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
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
import fetch from 'node-fetch'
import { FlatfileRecord, FlatfileRecords } from '@flatfile/hooks'
import {
Sheet,
Workbook,
TextField,
BooleanField,
NumberField,
OptionField,
Message,
} from '@flatfile/configure'
const Employees = new Sheet(
'Employees',
{
firstName: TextField({
required: true,
description: 'Given name',
}),
lastName: TextField(),
fullName: TextField(),
stillEmployed: BooleanField(),
department: OptionField({
label: 'Department',
options: {
engineering: 'Engineering',
hr: 'People Ops',
sales: 'Revenue',
},
}),
fromHttp: TextField({ label: 'Set by batchRecordCompute' }),
salary: NumberField({
label: 'Salary',
description: 'Annual Salary in USD',
required: true,
validate: (salary: number) => {
const minSalary = 30_000
if (salary < minSalary) {
return [
new Message(
`${salary} is less than minimum wage ${minSalary}`,
'warn',
'validate'
),
]
}
},
}),
},
{
allowCustomFields: true,
readOnly: true,
recordCompute: (record) => {
const fullName = `{record.get('firstName')} {record.get('lastName')}`
record.set('fullhName', fullName)
return record
},
batchRecordsCompute: async (payload: FlatfileRecords<any>) => {
const response = await fetch('https://api.us.flatfile.io/health', {
method: 'GET',
headers: {
Accept: 'application/json',
},
})
const result = await response.json()
payload.records.map(async (record: FlatfileRecord) => {
await record.set('fromHttp', result.info.postgres.status)
})
},
}
)
export default new Workbook({
name: 'Migration stage1',
namespace: 'MyCompany',
sheets: {
Employees,
},
})