Core Logic of the Create Lambda

Learn about the core logic of the Create Lambda, and write different tests for the code.

Overview

We’ve learned how to create simple Lambda code. Let’s understand the core logic of how to create it. Instead of writing validations, we’ll work on the core logic of our Create Lambda. We must do at least two things with the event we receive. One is, obviously, storing it somewhere. That’s something we’ll mock for now, but we’ll come back to that shortly. The other part is called transformations, which involves modifying the data we have.

We may have noticed there’s no price included in the event. Because we don’t completely trust the information coming from the frontend, we want to calculate the price in the backend, based on the dates we received. We’ll start with that. Our CreateReservationRequest has now been validated, so we can use that as a starting point. We’ll also assume a flat rate of 20 euros for every night. Let’s add a file, priceCalculationTest.ts, to our specifics test folder:

Get hands-on with 1200+ tech skills courses.