0:00 All right. So in this lecture, we're gonna look at how we can implement 0:04 the opposite side of our adapter here, so that when we get 0:08 records from the database, our order records, we can convert them 0:11 back into the order entity that our domain model expects. 0:15 So 0:16 for this, let's go ahead, and just as we did for the inverse where 0:20 we 0:20 took toOrderPersistence, a new method, 0:24 and for toItem, what we're gonna do is implement a new 0:28 private 0:30 static toDomain method. 0:33 This will get passed in the underlying order row of type 0:37 OrderRow. And we know that this order 0:41 row is going to be type of 0:42 Orders.inferSelect, which is gonna be the 0:46 return statement from the database based off of our schema. 0:50 So what's so nice is that this type here automatically updates 0:54 whenever we change our schema, always ensuring our code is 0:58 correct. 0:59 So we have the order row here, and additionally, we're also gonna get 1:03 passed the item rows, which are gonna be the underlying 1:07 order items for this order that exist in the database. 1:11 So this will be type of 1:13 OrderItems.inferSelect 1:17 array value. And for our return type, we will return 1:21 back the OrderEntity. 1:24 So now the first thing that we're gonna do 1:26 is create the underlying 1:28 order item. So for this, we will map over 1:32 our item rows and destructure each one 1:36 here. So now we'll map over it and prepare to 1:40 reconstitute the order item. For this, the first thing we need to 1:44 do is determine if there's a discount for this order item. 1:48 So for this, we'll check discount, 1:51 and we'll look at our order item row and see if discountAmount 1:55 does od-- equal null. So we have an amount, and the 1:59 row discountCurrency also does not equal 2:03 null. This means we know we have a discount,
The rest of the transcript is for members.
Sign in