Created
June 8, 2020 15:05
-
-
Save claym/e38818e80fc4fc7f6a2bd282d56a5a7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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