-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtalent-form-data-fetching.ts
32 lines (29 loc) · 1.08 KB
/
talent-form-data-fetching.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
import {
AddressFormAPIResponse,
AddressFormResponseData,
fetchFieldByString,
fetchRawFormResponse,
} from './addressform-data-fetching-utils';
export const TALENT_FORM_ID = '5dd40741-aa26-49ae-88d4-ad4ed4c854af';
/**
* Fetch talent from data from AddressForm API
*/
export const fetchTalentFormData = async () => {
return postProcessTalentApiResponse(await fetchRawFormResponse(TALENT_FORM_ID));
};
const postProcessTalentApiResponse = (rawTalentData: AddressFormAPIResponse) => {
return rawTalentData.responses.map(data => {
const responseData = data.response_data;
const metadata = JSON.parse(data.metadata);
return {
name: fetchFieldByString(responseData, 'name'),
twitter: (fetchFieldByString(responseData, 'twitter') ?? '')
.replace('@', '')
.replace('https://twitter.com/', ''),
discord: fetchFieldByString(responseData, 'discord'),
discordId: metadata && metadata.user_id ? metadata.user_id : '',
title: [fetchFieldByString(responseData, 'Vocation')],
skills: fetchFieldByString(responseData, 'skills'),
};
});
};