Skip to content

Instantly share code, notes, and snippets.

@claym
Created June 8, 2020 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claym/e38818e80fc4fc7f6a2bd282d56a5a7c to your computer and use it in GitHub Desktop.
Save claym/e38818e80fc4fc7f6a2bd282d56a5a7c to your computer and use it in GitHub Desktop.
export const hello: APIGatewayProxyHandler = async (event, _context) => {
FantasyDataClient.Soccerv3ScoresClient.getCompetitionHierarchyLeagueHierarchyPromise()
.then((resp: string) => {
var data = JSON.parse(resp);
return data;
})
.then((data: Area[]) => {
let areaInputs: AreaInput[] = [];
data.map((area) => {
let areaInput = convertArea(area);
areaInputs.push(areaInput);
});
return areaInputs;
})
.then((areas: AreaInput[]) => {
console.log("areas ", areas);
client.mutate({
mutation: insertArea,
variables: { areas: areas },
});
});
return {
statusCode: 200,
body: JSON.stringify(
{
message:
"Go Serverless Webpack (Typescript) v1.0! Your function executed successfully!",
input: event,
},
null,
2
),
};
};
const convertArea = async (sdArea: Area): Promise<AreaInput> => {
return new Promise(function (resolve, reject) {
let area: AreaInput;
area = {
id: sdArea.AreaId,
countryCode: sdArea.CountryCode,
name: sdArea.Name,
};
return area;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment