1 00:00:00,620 --> 00:00:04,970 Time for us to start moving code from our OTT service over to the common service. 2 00:00:05,010 --> 00:00:07,520 So let's get to it inside the auto service. 3 00:00:07,520 --> 00:00:12,470 There are really two directories inside of here that we probably want to reuse between many other services 4 00:00:12,560 --> 00:00:16,580 across our entire project and that is the air directories and middleware. 5 00:00:17,050 --> 00:00:22,810 So I want to take those two folders and move them over to the SRT directory inside of our common module. 6 00:00:23,000 --> 00:00:27,480 To do so I can either do a simple drag and drop or I could cut and paste both of these. 7 00:00:27,710 --> 00:00:29,680 I'll do a simple drag and drop. 8 00:00:29,680 --> 00:00:39,280 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. 9 00:00:39,290 --> 00:00:43,880 If you are still running scaffold on your machine scaffold it is going to start to go insane because 10 00:00:43,880 --> 00:00:46,160 it's going to try to build all these changes. 11 00:00:46,160 --> 00:00:50,000 And lo and behold you now have a lot of missing files inside the service. 12 00:00:50,450 --> 00:00:54,810 So I would encourage you to stop scaffold at this point in time. 13 00:00:54,900 --> 00:00:55,200 All right. 14 00:00:55,200 --> 00:00:59,700 So back inside of Coleman now we've got these two files are these two folders with a ton of files inside 15 00:00:59,700 --> 00:01:02,060 them now at some point time. 16 00:01:02,070 --> 00:01:07,050 We're going to want to imports all these files into some other module for example inside of our off 17 00:01:07,430 --> 00:01:08,040 project. 18 00:01:08,100 --> 00:01:14,550 We're going to want to import specifically that bad Request air going to open up the index dot to yes 19 00:01:14,550 --> 00:01:16,550 file to delete everything inside of here. 20 00:01:16,560 --> 00:01:21,780 And I want to just show you something that we need to keep in mind so inside of our auth module we're 21 00:01:21,780 --> 00:01:26,820 going to eventually want to import bad request air and we need to figure out how we want to import that. 22 00:01:26,820 --> 00:01:29,780 In other words what path do we actually want to write. 23 00:01:29,790 --> 00:01:31,560 There's two ways we could do this. 24 00:01:31,560 --> 00:01:38,400 We can either set everything up so that we have to write out something like import bad Request air from 25 00:01:40,190 --> 00:01:44,370 SGI ticketing common errors bad request error. 26 00:01:44,450 --> 00:01:48,080 That's option number one or we can also set everything up. 27 00:01:48,080 --> 00:01:55,860 So we only have to do something like bad request error from SGI ticketing common. 28 00:01:55,910 --> 00:02:00,590 Those are the two options now option number one up here is a lot easier to do. 29 00:02:00,590 --> 00:02:05,450 We could essentially just publish our code as it stands right now and this would pretty much work. 30 00:02:05,720 --> 00:02:09,890 The bad thing about this approach is that anyone who uses our common module is going to have to know 31 00:02:09,890 --> 00:02:14,090 about the different directories and different files inside of our project. 32 00:02:14,090 --> 00:02:17,440 So it'd be a little bit nicer for the people who are actually using our library. 33 00:02:17,510 --> 00:02:20,750 They could write out a simple import statement like this right here. 34 00:02:20,840 --> 00:02:22,270 So how do we enable this behavior. 35 00:02:22,280 --> 00:02:24,020 How do we actually set this up. 36 00:02:24,110 --> 00:02:31,400 Well to delete all this to make sure that is available or allow our users of our module to do that we're 37 00:02:31,400 --> 00:02:37,850 going to import everything inside these different files and export it from the index dot to yes file. 38 00:02:38,570 --> 00:02:40,850 So it's going to be kind of a little bit of repetitive code. 39 00:02:40,850 --> 00:02:44,960 We're going to have to import all these different files inside of here and then export everything we 40 00:02:44,960 --> 00:02:46,160 imported. 41 00:02:46,160 --> 00:02:49,390 Let me show you how we do that inside of index dot. 42 00:02:49,410 --> 00:02:50,130 Yes. 43 00:02:50,220 --> 00:02:58,440 Well first begin with that bad request error file so I can write out export star from air's bad requester 44 00:02:59,830 --> 00:03:05,500 that's going to import everything from battery Quest air and then immediately re export it from this 45 00:03:05,500 --> 00:03:06,530 file. 46 00:03:06,670 --> 00:03:11,170 So we have to write out this line right here where everything that we want to export directly out of 47 00:03:11,170 --> 00:03:12,690 the index ought to yes file. 48 00:03:12,700 --> 00:03:18,210 So essentially one line for every file that let's get to it. 49 00:03:18,210 --> 00:03:23,640 We're going to copy that line right there aced it down and we're pretty much just going to go down this 50 00:03:23,700 --> 00:03:32,430 file list the next one is customer after that is database connection error 51 00:03:36,620 --> 00:03:38,390 not authorized air 52 00:03:42,110 --> 00:03:43,730 not found error 53 00:03:47,930 --> 00:03:51,760 request validation error. 54 00:03:51,780 --> 00:03:58,490 Now we'll go on to the middleware directory so I can make sure I update the folder to middle. 55 00:03:58,880 --> 00:04:00,420 And that we'll do a current user 56 00:04:04,760 --> 00:04:05,870 air handler 57 00:04:09,710 --> 00:04:16,330 require off and validate request every go 58 00:04:21,800 --> 00:04:24,290 while still not done just yet. 59 00:04:24,290 --> 00:04:28,190 Let's try to build our project with typescript really quickly and we're gonna see a bunch of errors 60 00:04:28,190 --> 00:04:28,910 pop up. 61 00:04:28,910 --> 00:04:32,750 Now what do you see these areas just to understand what we have to do next and how we're going to solve 62 00:04:32,750 --> 00:04:33,420 it. 63 00:04:33,540 --> 00:04:39,090 So I can go back over to my terminal inside of common I'm going to try to build my project directory 64 00:04:39,120 --> 00:04:43,280 by just running TSC and as soon as I do so yep. 65 00:04:43,340 --> 00:04:44,410 Bunch of errors. 66 00:04:44,600 --> 00:04:46,100 So why are we seeing this. 67 00:04:46,100 --> 00:04:50,690 Well inside of a lot of these different files we are making assumptions about the different modules 68 00:04:50,720 --> 00:04:54,620 that we have available to or are available to us inside of this package. 69 00:04:54,620 --> 00:05:00,500 So for example inside of say the current user middleware we are trying to import Express and Jason web 70 00:05:00,500 --> 00:05:05,460 token we had all these modules installed back inside of off. 71 00:05:05,460 --> 00:05:07,530 So everything worked out just okay over there. 72 00:05:07,680 --> 00:05:12,000 But now that they are defined inside of comment we have to actually install these modules into Carmen 73 00:05:12,210 --> 00:05:16,920 to make these Middleware is actually where correctly so we pretty much have to go through all these 74 00:05:16,920 --> 00:05:22,050 files we have to take a look at all the imports we have and then install them into this project so we 75 00:05:22,050 --> 00:05:29,260 can actually build this stuff with typescript tells you that right away back about terminal we're going 76 00:05:29,260 --> 00:05:34,880 to do an empty install and we're going to get a pretty hefty list of modules here. 77 00:05:35,060 --> 00:05:38,990 So we're going to get Express Express validator 78 00:05:41,730 --> 00:05:47,310 we will get cookie session and then Jason web token. 79 00:05:47,680 --> 00:05:53,400 We're also going to install a couple of type definition files as well so I'll get at types cookie session 80 00:05:54,240 --> 00:05:54,900 at types. 81 00:05:54,900 --> 00:06:01,990 EXPRESS At types Jason web token and I think that's about it. 82 00:06:02,830 --> 00:06:07,300 EXPRESS validator has its own included type definition files so we do not have to install that success 83 00:06:07,300 --> 00:06:11,470 first me separately it's let's run that command 84 00:06:14,480 --> 00:06:23,710 and now if we tried to do a typescript compile or TSC everything will be built successfully. 85 00:06:23,730 --> 00:06:28,010 Well I think we are now ready to try to build this module and publish it. 86 00:06:28,260 --> 00:06:33,020 So as we saw in the last video we put together that nice little script of pub right here. 87 00:06:33,420 --> 00:06:39,510 Let's run NPM run pub that's going to build our project committed publish it up to NPM and we'll be 88 00:06:39,510 --> 00:06:42,620 able to install it into our off service and start to fix up. 89 00:06:42,630 --> 00:06:51,000 Off to use the code we have now inside this module so I'll do an NPM run pub that's going to commit 90 00:06:51,040 --> 00:06:59,260 our changes clean build and push. 91 00:06:59,320 --> 00:06:59,730 There we go. 92 00:07:01,270 --> 00:07:01,480 All right. 93 00:07:01,490 --> 00:07:02,800 So that's pretty much it. 94 00:07:03,100 --> 00:07:07,360 We've got our coming module put together now we are going to come back to the come module over time 95 00:07:07,390 --> 00:07:12,100 and add in a lot more code to this thing specifically we're going to add in a lot of code to the coming 96 00:07:12,100 --> 00:07:15,760 module around handling and publishing events through our event bus. 97 00:07:16,060 --> 00:07:19,450 But right now it is a middleware is pretty much good enough. 98 00:07:19,690 --> 00:07:20,900 Well let's take a pause right here. 99 00:07:20,920 --> 00:07:25,330 When come back next video we're gonna go back over to our auth project we're going to install this common 100 00:07:25,330 --> 00:07:28,240 module and fix up a lot of import statements inside their.