1 00:00:01,290 --> 00:00:03,510 Let's move on to grading our ticket schema. 2 00:00:03,620 --> 00:00:10,110 So after those three interfaces I'm going to add in ticket schema is new Mongoose schema 3 00:00:12,960 --> 00:00:15,750 as the first argument we're going to provide an object inside of here. 4 00:00:15,750 --> 00:00:18,420 We're gonna list out all the different properties that we want this thing to have. 5 00:00:18,810 --> 00:00:26,600 So we wanted to have a title its type is going to be string and it is required we'll say it required 6 00:00:26,690 --> 00:00:28,840 true as a quick reminder. 7 00:00:28,850 --> 00:00:31,800 Right here we are listing out an actual value type. 8 00:00:31,820 --> 00:00:35,640 So this type thing right here is used by Mongoose not typescript. 9 00:00:35,660 --> 00:00:40,150 So when we say string right here we are referring to the global string constructor in JavaScript and 10 00:00:40,150 --> 00:00:44,260 that means we should have a capital S in all these interfaces up here. 11 00:00:44,260 --> 00:00:49,260 We're referring to a type as far as typescript is concerned this is a type specifically for typescript 12 00:00:49,530 --> 00:00:51,340 we use lowercase s up here 13 00:00:54,960 --> 00:00:56,040 beside the title. 14 00:00:56,040 --> 00:01:00,750 We will also have a price its title or assuming its type will be a number. 15 00:01:00,800 --> 00:01:11,020 And again capital N required true then finally a user I.D. its type will be string. 16 00:01:11,240 --> 00:01:12,830 It is required. 17 00:01:12,830 --> 00:01:20,850 And that's it now as the second argument into Mongoose schema we're gonna put in another object and 18 00:01:20,850 --> 00:01:25,820 this is where we're going to put in that custom to Jason function is remember we want to massage that 19 00:01:25,830 --> 00:01:34,310 idea property so we're going to add inside of the second argument to Jason I'll define the transform 20 00:01:34,310 --> 00:01:40,200 function and recall this thing takes two arguments Doc and ret. 21 00:01:40,210 --> 00:01:43,810 So red is gonna be the object that's just about to be turned in to Jason. 22 00:01:43,900 --> 00:01:46,630 So we're going to make some direct changes to that red object. 23 00:01:46,690 --> 00:01:51,520 We're not trying to return anything from the thing we're trying to modify red directly. 24 00:01:51,570 --> 00:01:57,300 So again we're going to assign the red dot idea property from Red Dot underscore I.D. and then we will 25 00:01:57,300 --> 00:02:00,270 delete red dot underscore i.e. 26 00:02:04,470 --> 00:02:11,780 that looks good after that we're going to build up that build method on our ticket schema the ticket 27 00:02:11,780 --> 00:02:15,200 schema dot static stop build. 28 00:02:15,210 --> 00:02:18,170 So this is going to be the one and only way that we create new records. 29 00:02:18,180 --> 00:02:23,040 Again just to make sure that we can typescript helping us figure out the different types of attributes 30 00:02:23,140 --> 00:02:32,470 responsibly providing we'll take in adders of type ticket adders and then we'll return new ticket and 31 00:02:32,470 --> 00:02:36,040 passing those adders and I love to s out of that argument right there. 32 00:02:36,040 --> 00:02:41,230 We merely get an air out of that that's truly okay we're gonna fix that up in just a moment so after 33 00:02:41,220 --> 00:02:47,850 we define that build method we will create the actual ticket model that's going to be Mongoose dot model 34 00:02:49,300 --> 00:02:50,590 we're gonna put in some generic types. 35 00:02:50,590 --> 00:02:58,340 This thing of ticket Doc and ticket model will then call the actual function we'll provide a name for 36 00:02:58,340 --> 00:03:05,180 the collection of tickets and the second argument is gonna be our schema to use which is ticket schema. 37 00:03:05,240 --> 00:03:09,200 I'll say that it does not wrap the line so clubs that sidebar. 38 00:03:09,200 --> 00:03:19,440 There we go and finally very last up let's export horsemeat not expect export not ticket and that should 39 00:03:19,440 --> 00:03:19,710 be at 40 00:03:22,730 --> 00:03:22,940 okay. 41 00:03:22,940 --> 00:03:28,860 So we're all done with our ticket now now that we've got that ticket model put together we can actually 42 00:03:28,890 --> 00:03:34,980 save data and retrieve data from our Mongo database to back inside of our new test file. 43 00:03:35,000 --> 00:03:38,900 Remember we've still got this comment right here reminding us that we need to make sure that somehow 44 00:03:38,930 --> 00:03:40,400 that ticket was saved. 45 00:03:40,490 --> 00:03:41,560 So we'll take a pause right here. 46 00:03:41,570 --> 00:03:45,770 We're going to implement this little check right here in the next video and we'll build out the actual 47 00:03:45,770 --> 00:03:48,380 implementation inside of our request handler itself.