Time for us to start moving code from our OTT service over to the common service.
So let's get to it inside the auto service.
There are really two directories inside of here that we probably want to reuse between many other services
across our entire project and that is the air directories and middleware.
So I want to take those two folders and move them over to the SRT directory inside of our common module.
To do so I can either do a simple drag and drop or I could cut and paste both of these.
I'll do a simple drag and drop.
So I'm going to drag errors over to s RC and Middleware is over to SC as well now as soon as I do so.
If you are still running scaffold on your machine scaffold it is going to start to go insane because
it's going to try to build all these changes.
And lo and behold you now have a lot of missing files inside the service.
So I would encourage you to stop scaffold at this point in time.
All right.
So back inside of Coleman now we've got these two files are these two folders with a ton of files inside
them now at some point time.
We're going to want to imports all these files into some other module for example inside of our off
project.
We're going to want to import specifically that bad Request air going to open up the index dot to yes
file to delete everything inside of here.
And I want to just show you something that we need to keep in mind so inside of our auth module we're
going to eventually want to import bad request air and we need to figure out how we want to import that.
In other words what path do we actually want to write.
There's two ways we could do this.
We can either set everything up so that we have to write out something like import bad Request air from
SGI ticketing common errors bad request error.
That's option number one or we can also set everything up.
So we only have to do something like bad request error from SGI ticketing common.
Those are the two options now option number one up here is a lot easier to do.
We could essentially just publish our code as it stands right now and this would pretty much work.
The bad thing about this approach is that anyone who uses our common module is going to have to know
about the different directories and different files inside of our project.
So it'd be a little bit nicer for the people who are actually using our library.
They could write out a simple import statement like this right here.
So how do we enable this behavior.
How do we actually set this up.
Well to delete all this to make sure that is available or allow our users of our module to do that we're
going to import everything inside these different files and export it from the index dot to yes file.
So it's going to be kind of a little bit of repetitive code.
We're going to have to import all these different files inside of here and then export everything we
imported.
Let me show you how we do that inside of index dot.
Yes.
Well first begin with that bad request error file so I can write out export star from air's bad requester
that's going to import everything from battery Quest air and then immediately re export it from this
file.
So we have to write out this line right here where everything that we want to export directly out of
the index ought to yes file.
So essentially one line for every file that let's get to it.
We're going to copy that line right there aced it down and we're pretty much just going to go down this
file list the next one is customer after that is database connection error
not authorized air
not found error
request validation error.
Now we'll go on to the middleware directory so I can make sure I update the folder to middle.
And that we'll do a current user
air handler
require off and validate request every go
while still not done just yet.
Let's try to build our project with typescript really quickly and we're gonna see a bunch of errors
pop up.
Now what do you see these areas just to understand what we have to do next and how we're going to solve
it.
So I can go back over to my terminal inside of common I'm going to try to build my project directory
by just running TSC and as soon as I do so yep.
Bunch of errors.
So why are we seeing this.
Well inside of a lot of these different files we are making assumptions about the different modules
that we have available to or are available to us inside of this package.
So for example inside of say the current user middleware we are trying to import Express and Jason web
token we had all these modules installed back inside of off.
So everything worked out just okay over there.
But now that they are defined inside of comment we have to actually install these modules into Carmen
to make these Middleware is actually where correctly so we pretty much have to go through all these
files we have to take a look at all the imports we have and then install them into this project so we
can actually build this stuff with typescript tells you that right away back about terminal we're going
to do an empty install and we're going to get a pretty hefty list of modules here.
So we're going to get Express Express validator
we will get cookie session and then Jason web token.
We're also going to install a couple of type definition files as well so I'll get at types cookie session
at types.
EXPRESS At types Jason web token and I think that's about it.
EXPRESS validator has its own included type definition files so we do not have to install that success
first me separately it's let's run that command
and now if we tried to do a typescript compile or TSC everything will be built successfully.
Well I think we are now ready to try to build this module and publish it.
So as we saw in the last video we put together that nice little script of pub right here.
Let's run NPM run pub that's going to build our project committed publish it up to NPM and we'll be
able to install it into our off service and start to fix up.
Off to use the code we have now inside this module so I'll do an NPM run pub that's going to commit
our changes clean build and push.
There we go.
All right.
So that's pretty much it.
We've got our coming module put together now we are going to come back to the come module over time
and add in a lot more code to this thing specifically we're going to add in a lot of code to the coming
module around handling and publishing events through our event bus.
But right now it is a middleware is pretty much good enough.
Well let's take a pause right here.
When come back next video we're gonna go back over to our auth project we're going to install this common
module and fix up a lot of import statements inside their.