1 00:00:01,420 --> 00:00:03,160 All right let's open up our payment service. 2 00:00:03,160 --> 00:00:07,900 We're going to create a new model file and we're going to make sure that we replicate these five properties 3 00:00:07,900 --> 00:00:08,490 right here. 4 00:00:08,530 --> 00:00:12,520 I should say that we are going to store these five properties tied to every order inside the payment 5 00:00:12,520 --> 00:00:13,560 service. 6 00:00:13,700 --> 00:00:19,000 So back inside my editor I got to find the payments directory I'll find the SRS folder inside there 7 00:00:19,120 --> 00:00:24,460 and then I'll make a new directory called models and inside that I'll make a new file called Order. 8 00:00:24,500 --> 00:00:32,940 Yes as usual at the very top I will import Mongoose from Mongoose and then we will define our three 9 00:00:33,000 --> 00:00:35,840 separate interfaces. 10 00:00:36,070 --> 00:00:41,800 It's our first interface will be order adders then order duck. 11 00:00:41,830 --> 00:00:44,680 And that's going to be extending Mongoose dot document 12 00:00:47,770 --> 00:00:50,540 and then order model. 13 00:00:50,730 --> 00:00:53,520 And that's going to be extending Mongoose stock model. 14 00:00:53,590 --> 00:01:00,690 This is a generic and we'll put in order duck like so these three interfaces they serve the same goal 15 00:01:00,690 --> 00:01:01,750 they always have. 16 00:01:01,770 --> 00:01:05,180 First one is a list of properties we have to provide when building in order. 17 00:01:05,190 --> 00:01:07,720 The second one is the list of properties that an order has. 18 00:01:07,740 --> 00:01:11,520 And then finally the list of properties that the model itself contains. 19 00:01:11,640 --> 00:01:16,430 So this is going to list out any custom methods we add to the overall collection and so on. 20 00:01:16,450 --> 00:01:16,980 Let's get to it. 21 00:01:16,980 --> 00:01:21,340 We're going to go through and fill out each of these interfaces essentially using the same properties 22 00:01:21,400 --> 00:01:28,020 that we just spoke about over here so whenever we create a new order we have to specify the idea of 23 00:01:28,020 --> 00:01:30,260 that order as a string. 24 00:01:30,540 --> 00:01:36,570 We have to specify the about version user idea and price will come back to status in just a moment. 25 00:01:36,570 --> 00:01:43,240 So version is definitely to be a no user ideally a string and price will be a number as well diversion 26 00:01:43,270 --> 00:01:44,320 is a number. 27 00:01:44,680 --> 00:01:48,970 User I.D. is a string and price is a number and instead. 28 00:01:49,000 --> 00:01:52,700 You might recall we had created that order status income inside of our common module. 29 00:01:52,710 --> 00:01:55,330 That list out all the different possible statuses in order could have. 30 00:01:56,260 --> 00:02:01,780 So for our status we're going to say that this must be one of the possible in some cases or one the 31 00:02:01,780 --> 00:02:04,360 possible cases listed inside of our order status. 32 00:02:04,700 --> 00:02:12,030 So for that at the very top we will import our order status enum from our common module and then use 33 00:02:12,030 --> 00:02:16,750 that enum like so. 34 00:02:16,790 --> 00:02:18,960 Next up will work on the order document. 35 00:02:19,130 --> 00:02:23,480 Right now the order duck is going to look absolutely identical in nature except we're not going to list 36 00:02:23,480 --> 00:02:24,890 out the idea right here. 37 00:02:24,890 --> 00:02:29,630 No we only list I.D. inside the order adders to say that whenever we wanted to create an order we must 38 00:02:29,630 --> 00:02:35,720 provide it provide an I.D. but when we write out the order duck the Mongoose document interface right 39 00:02:35,720 --> 00:02:40,450 here that we are extending already includes or defines the idea of an I.D. property. 40 00:02:40,460 --> 00:02:45,560 So we do not have to realestate down inside the order interface is it is essentially already listed 41 00:02:45,590 --> 00:02:47,520 inside of that interface. 42 00:02:47,610 --> 00:02:51,460 Will put inversion that is a number user I.D.. 43 00:02:51,480 --> 00:02:53,670 That is a string right. 44 00:02:53,670 --> 00:03:00,180 That is a number and status that is of type order status. 45 00:03:00,180 --> 00:03:01,680 Finally our order model. 46 00:03:01,680 --> 00:03:04,750 So as usual we're just gonna say that this thing should have a build method. 47 00:03:04,830 --> 00:03:10,710 That's going to take in some object of type order adders and then return an instance of an order duck 48 00:03:11,720 --> 00:03:13,890 to the list out built. 49 00:03:13,930 --> 00:03:21,430 This will take something of type order adders and then return something of type order duck. 50 00:03:21,550 --> 00:03:24,460 Let's now start to define the actual schema itself. 51 00:03:24,670 --> 00:03:28,970 We'll make a new order schema variable. 52 00:03:29,000 --> 00:03:34,270 This will be a new Mongoose dot schema and then inside of here we're gonna list out all the different 53 00:03:34,270 --> 00:03:35,030 properties. 54 00:03:35,170 --> 00:03:39,930 And it's going to roughly be the same as a we list out inside of order duck. 55 00:03:39,990 --> 00:03:44,140 Really big difference is that we're not going to include the version because remember the version property 56 00:03:44,140 --> 00:03:48,850 is going to be maintained automatically by the Mongoose update if current module which we'll we will 57 00:03:48,850 --> 00:03:56,230 eventually install and wire up to this document so we're going to list out user I.D. that's going to 58 00:03:56,230 --> 00:03:57,080 be a string. 59 00:03:57,100 --> 00:04:01,960 And remember because we are inside of a schema definition here we are using capital as string because 60 00:04:01,960 --> 00:04:04,270 this is not an interface we are writing right now. 61 00:04:04,270 --> 00:04:11,020 It is not typescript not required to put lowercase S. it must be capital S we also say that is required 62 00:04:11,020 --> 00:04:15,930 to provide a user I.D. So required is true. 63 00:04:15,940 --> 00:04:25,990 Next up is our price that is going to be a number also required and then finally a status and we'll 64 00:04:25,990 --> 00:04:30,560 say that this is going to be a string and it is required as well. 65 00:04:30,600 --> 00:04:34,120 You may recall that back on our order service and we defined the order model. 66 00:04:34,200 --> 00:04:38,760 We used a little trick to make sure that the value of status we provided was one of the values inside 67 00:04:38,760 --> 00:04:39,640 of the order enum. 68 00:04:39,750 --> 00:04:40,980 We could definitely do that here as well. 69 00:04:41,010 --> 00:04:45,790 But just to save some time I'm going to skip it gets there is our order schema or at least the different 70 00:04:45,790 --> 00:04:51,490 properties it's going to have now as the second argument as usual we are going to define that to Jason 71 00:04:51,550 --> 00:04:56,220 method just to make sure that we ever have to turn this thing to Jason send it over somewhere else. 72 00:04:56,320 --> 00:04:58,270 We provide the appropriate properties. 73 00:04:58,300 --> 00:05:04,690 We also want to make sure that we rename on the fly that underscore I.D. property as well so to defined 74 00:05:04,690 --> 00:05:06,610 that we're going to throw in here 75 00:05:09,460 --> 00:05:18,580 our to Jason section this allowed a transform method that receives the document and the return value 76 00:05:19,890 --> 00:05:34,510 we'll say that rent I.D. is rent dot underscore I.D. and then we will delete red dot underscore i.e.. 77 00:05:34,750 --> 00:05:37,270 Next up let's define our build method. 78 00:05:37,270 --> 00:05:41,670 We are skipping temporarily over that update of current plug in but we will come back to it. 79 00:05:41,970 --> 00:05:47,650 So our build method will be order schema that statics that builds. 80 00:05:47,810 --> 00:05:53,770 This is going to be a function that takes an argument of adders that must be of type order adders and 81 00:05:53,770 --> 00:05:59,130 then inside of here we're going to return a new order on the fly. 82 00:05:59,130 --> 00:06:04,050 We're going to pass through a couple of different properties to remember in particular this adders object 83 00:06:04,050 --> 00:06:09,270 right here is going to have an I.D. property but when we pass it into the constructor we must rename 84 00:06:09,270 --> 00:06:11,250 that thing to underscore I.D. instead 85 00:06:14,470 --> 00:06:21,680 we're gonna say that underscore I.D. is adders dot underscore I.D. or should be just normal I.D.. 86 00:06:21,710 --> 00:06:30,300 There we go the version for this the adders dot version we're then going to have a price from our stock 87 00:06:30,340 --> 00:06:37,420 price user I.D. from our start user I.D. and then what else are we missing here. 88 00:06:37,630 --> 00:06:42,300 Take a look at order adders status something is just status and that's it. 89 00:06:42,300 --> 00:06:51,000 So our status will be at our state status we are getting an air around order that will go away as soon 90 00:06:51,000 --> 00:06:54,660 as we define the actual model itself which let's do that right now. 91 00:06:54,660 --> 00:06:58,530 So order is going to be a mongoose dot model. 92 00:06:58,730 --> 00:07:06,470 We're going to feed in our two generic so order DAC order model make a new collection called order and 93 00:07:06,530 --> 00:07:07,900 then the order schema. 94 00:07:08,100 --> 00:07:09,390 And then finally at the very bottom. 95 00:07:09,470 --> 00:07:11,010 Export order. 96 00:07:11,390 --> 00:07:12,130 And that's it. 97 00:07:13,650 --> 00:07:15,120 Yeah I think we're good to go here. 98 00:07:15,120 --> 00:07:16,360 So let's take a quick pause. 99 00:07:16,400 --> 00:07:21,350 When we come back the next video we're gonna start to put together are two listeners which are going 100 00:07:21,350 --> 00:07:23,930 to listen for the order created and order cancel events. 101 00:07:23,930 --> 00:07:28,220 Whenever we receive those we're going to either create an order or cancel an existing order inside the 102 00:07:28,220 --> 00:07:29,030 orders collection.