Let's move on to grading our ticket schema.
So after those three interfaces I'm going to add in ticket schema is new Mongoose schema
as the first argument we're going to provide an object inside of here.
We're gonna list out all the different properties that we want this thing to have.
So we wanted to have a title its type is going to be string and it is required we'll say it required
true as a quick reminder.
Right here we are listing out an actual value type.
So this type thing right here is used by Mongoose not typescript.
So when we say string right here we are referring to the global string constructor in JavaScript and
that means we should have a capital S in all these interfaces up here.
We're referring to a type as far as typescript is concerned this is a type specifically for typescript
we use lowercase s up here
beside the title.
We will also have a price its title or assuming its type will be a number.
And again capital N required true then finally a user I.D. its type will be string.
It is required.
And that's it now as the second argument into Mongoose schema we're gonna put in another object and
this is where we're going to put in that custom to Jason function is remember we want to massage that
idea property so we're going to add inside of the second argument to Jason I'll define the transform
function and recall this thing takes two arguments Doc and ret.
So red is gonna be the object that's just about to be turned in to Jason.
So we're going to make some direct changes to that red object.
We're not trying to return anything from the thing we're trying to modify red directly.
So again we're going to assign the red dot idea property from Red Dot underscore I.D. and then we will
delete red dot underscore i.e.
that looks good after that we're going to build up that build method on our ticket schema the ticket
schema dot static stop build.
So this is going to be the one and only way that we create new records.
Again just to make sure that we can typescript helping us figure out the different types of attributes
responsibly providing we'll take in adders of type ticket adders and then we'll return new ticket and
passing those adders and I love to s out of that argument right there.
We merely get an air out of that that's truly okay we're gonna fix that up in just a moment so after
we define that build method we will create the actual ticket model that's going to be Mongoose dot model
we're gonna put in some generic types.
This thing of ticket Doc and ticket model will then call the actual function we'll provide a name for
the collection of tickets and the second argument is gonna be our schema to use which is ticket schema.
I'll say that it does not wrap the line so clubs that sidebar.
There we go and finally very last up let's export horsemeat not expect export not ticket and that should
be at
okay.
So we're all done with our ticket now now that we've got that ticket model put together we can actually
save data and retrieve data from our Mongo database to back inside of our new test file.
Remember we've still got this comment right here reminding us that we need to make sure that somehow
that ticket was saved.
So we'll take a pause right here.
We're going to implement this little check right here in the next video and we'll build out the actual
implementation inside of our request handler itself.