Created
December 6, 2023 11:43
-
-
Save tarasowski/4ea4ea4895a7ed95e94f7e2243bc24cd to your computer and use it in GitHub Desktop.
median-price-calculator.mjs
This file contains hidden or 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 medianPriceCalculator = async (event) => { | |
| let region = event.region; | |
| let medianPrice; | |
| // Define median prices for US, CA and BR | |
| const medianPrices = { | |
| US: 320000.0, | |
| CA: 240000.0, | |
| BR: 260000.0, | |
| }; | |
| // Check if the input region is valid and retrieve the corresponding median price | |
| if (medianPrices.hasOwnProperty(region)) { | |
| medianPrice = medianPrices[region]; | |
| } else { | |
| medianPrice = medianPrices.US; // default to US median price if region is unknown | |
| region = 'UNKNOWN REGION'; | |
| } | |
| // Construct the response object | |
| const response = { | |
| statusCode: 200, | |
| body: JSON.stringify({region: region, medianPrice: medianPrice}), | |
| headers: { | |
| 'X-Powered-By': 'AWS API Gateway & Lambda' | |
| }, | |
| isBase64Encoded: false | |
| }; | |
| return response; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment