WEBVTT

00:03.760 --> 00:04.660
Hey, did everyone.

00:04.690 --> 00:05.200
They sure.

00:05.200 --> 00:06.670
And welcome to another video.

00:07.030 --> 00:09.490
In this video, we are going to finally start our journey.

00:09.490 --> 00:13.990
We have already designed our model and all the features that we wanted to to work in the model.

00:14.050 --> 00:19.360
Now, let me again remind you that the user model usually is the most difficult one after that, the

00:19.360 --> 00:24.760
products and orders or whatever else you are selling or trying to build an application that doesn't

00:24.760 --> 00:27.820
go with that much of complexity that we have worked on with these methods.

00:27.820 --> 00:31.960
But again, if something makes sense to you that yeah, this is something which needs to go as a method

00:31.960 --> 00:35.740
inside the model itself, please don't hesitate and always put that up there.

00:36.100 --> 00:42.160
So let's go up here now further down the road now we need to create a lot of routes and methods controllers

00:42.160 --> 00:42.580
for that.

00:42.580 --> 00:46.000
And again, I cannot just blindly go ahead and write all these methods.

00:46.240 --> 00:49.000
I need to have a plan that what we are going to build up.

00:49.000 --> 00:53.740
So in this case, what I have done is I have tried to kind of a mind map the things that how this is

00:53.740 --> 00:54.540
going to work.

00:54.550 --> 00:59.080
So in the previous one, we saw that we have a models, we will be working on user product and order

00:59.080 --> 01:01.420
and we have placed some sticky notes on that.

01:01.420 --> 01:06.520
Now these mind mapping actually always vary on based on what software I'm using or what kind of things

01:06.520 --> 01:07.030
I mean.

01:07.030 --> 01:08.920
But again, they remain almost the same.

01:08.920 --> 01:10.450
So we have done with this model.

01:10.480 --> 01:15.310
Now obviously each model is going to be following up some routes that when you visit these routes,

01:15.640 --> 01:20.230
this model will be mainly controlling these routes or will be affected by this route and there will

01:20.230 --> 01:22.120
be some controller associated with them.

01:22.120 --> 01:24.910
Now, there is no such big need of writing the name of controller.

01:24.910 --> 01:26.710
In case you do that, that is fantastic.

01:26.710 --> 01:28.060
Please go ahead and do that.

01:28.120 --> 01:33.280
Now, in this case, I have given some of the routes that I want to user to have a sign up functionality,

01:33.310 --> 01:40.330
a login, log out slash forgot password where he can request an email to have an instruction of how

01:40.330 --> 01:41.680
to reset the password.

01:42.100 --> 01:47.560
This is where we are going to learn about sending the emails and a whole lot of other things.

01:47.560 --> 01:51.010
And after that there is a slash password, slash research, slash token.

01:51.010 --> 01:53.050
You can name the route, whatever you like to have.

01:53.080 --> 01:58.360
The whole idea is to grab this unique string that we created earlier and I want to grab it from the

01:58.390 --> 01:59.380
URL itself.

01:59.380 --> 02:04.270
And then if the string matches with my database string, I will allow I will also request the password

02:04.270 --> 02:08.290
in the body as well so that everything can be resettled in the back end.

02:08.290 --> 02:10.060
Then this is going to be the user itself.

02:10.060 --> 02:13.630
So you want the information about all the information about the user itself.

02:13.660 --> 02:18.190
We will be allowing that this is where we are going to study about middleware and something interesting.

02:18.190 --> 02:23.920
And after that, if user want to update the password and if the user want to update any other information

02:23.920 --> 02:26.890
now, is there a need to separate these root?

02:26.920 --> 02:27.880
Probably not.

02:27.880 --> 02:32.680
You can actually just give a same page to the user that if he sends the password, just do this.

02:32.680 --> 02:36.070
If he doesn't send the password or send something else to update, you can allow that.

02:36.070 --> 02:40.210
But I'm going to keep them separate because this actually makes sense a little bit more to me and will

02:40.210 --> 02:42.160
make to you as well eventually in the future.

02:42.370 --> 02:42.910
Okay.

02:43.330 --> 02:48.040
So let's go ahead and set up the basic signup route and we'll talk more onto that.

02:48.040 --> 02:49.300
So let's go back up here.

02:49.510 --> 02:53.650
Now, the first thing is we are going to work on the controller, so let's go up here.

02:54.040 --> 02:58.930
So notice we have created the model for already there is already a home controller for that and we will

02:58.930 --> 03:01.150
be working on now is user controller.

03:01.150 --> 03:04.690
So I'll be saying user controller dogs of course.

03:04.870 --> 03:09.520
Now in this controller we don't need much, but we will be working on the model user quite a lot.

03:09.520 --> 03:11.110
So let's go ahead and bring that up.

03:11.110 --> 03:16.660
Now, this is kind of a functionality, not functionality, but kind of a regular data life thing of

03:16.660 --> 03:20.200
the user that always bring these models with the uppercase letter.

03:20.200 --> 03:25.120
This is kind of a convention and we are going to go ahead and say, hey, we want to require it and

03:25.120 --> 03:30.100
this will be one directory back inside the models and we have this user.

03:30.430 --> 03:34.660
So now we have this user again, we will be using it later on, not right now.

03:34.840 --> 03:36.640
So let's go ahead and export a method.

03:36.640 --> 03:40.570
So I'm going to go ahead and say export dot, sign up.

03:40.570 --> 03:42.280
This is a basic functionality.

03:42.310 --> 03:44.680
Now before we go ahead and do this, sign up.

03:44.680 --> 03:46.690
Actually, I would like to comment it for a second.

03:46.690 --> 03:50.080
We also need to bring up one other thing which is inside the utils.

03:50.080 --> 03:55.090
In case you remember, we have not in the utils in the middle where we are wrapping up around everything

03:55.090 --> 03:56.170
into this big promise.

03:56.170 --> 03:57.700
So we will be doing that now.

03:57.700 --> 04:00.010
So let's go ahead and import this big promise.

04:00.010 --> 04:09.160
So let's call this one as simply const big promise that will be coming up from require.

04:10.380 --> 04:12.360
Just like that one directory.

04:12.360 --> 04:16.170
Back inside the middleware, we have this big promise.

04:17.040 --> 04:18.320
Now, this is all up here.

04:18.330 --> 04:20.610
Let's go ahead and uncomment this one.

04:20.610 --> 04:22.080
So export sign up.

04:22.080 --> 04:26.190
And remember, we are wrapping up around everything inside this big promise.

04:26.190 --> 04:30.090
So let's go ahead and say, hey, this is a big promise and wrap everything around it.

04:30.180 --> 04:33.090
Now, inside this, you write your regular very basic method.

04:33.090 --> 04:36.090
Again, we will be working with the connecting with the database.

04:36.090 --> 04:38.310
And database is always on another continent.

04:38.310 --> 04:42.330
So we'll be working with the async and then writing our regular method.

04:42.330 --> 04:47.730
But make sure you also say that this is a request response and we also go ahead and pass on the next.

04:47.730 --> 04:50.880
We won't be using it, but maybe our promise might need it.

04:50.880 --> 04:54.510
And just for your information, the actual format is actually like this.

04:54.510 --> 05:00.120
We have the errors, the request and request and the response, and then we have the next.

05:00.120 --> 05:04.560
Since we are not using the error or we don't have any kind of a special handler for the error.

05:04.560 --> 05:06.570
So that's why we are working on this match only.

05:06.570 --> 05:09.360
But in some cases you might also see that part also.

05:09.720 --> 05:13.020
So let's go ahead and just wrap the function just like that.

05:13.020 --> 05:16.260
Told you a big promise is a thing which you create once and you forget about it.

05:16.260 --> 05:20.970
If anything goes wrong, it will handle it very nicely, but otherwise you just don't worry too much

05:20.970 --> 05:21.540
on that.

05:21.690 --> 05:23.880
I'll just add a comment here and that's it.

05:24.480 --> 05:29.250
We will be working on signup functionality in a minute, but first I want to go ahead and work on the

05:29.250 --> 05:30.150
roots itself.

05:30.150 --> 05:32.430
So let's go ahead and move on to the Roots.

05:32.430 --> 05:35.610
We'll create a new file which will handle all of our user roots.

05:35.610 --> 05:38.200
So we're going to call this one as just a user is.

05:38.700 --> 05:40.230
Now we need to create a router here.

05:40.230 --> 05:42.750
So again, router will be coming from the express itself.

05:42.750 --> 05:44.460
So shouldn't be a much of a worry.

05:44.790 --> 05:53.430
So let's go ahead and say, hey, I need X Press and Express is going to be coming from require express

05:53.550 --> 05:56.670
and let's go ahead and grab a router, not the app app.

05:56.670 --> 05:57.540
We do that in the app.

05:57.720 --> 05:59.940
JS But this time we need just the router.

06:00.030 --> 06:07.020
So we're going to go ahead and say, hey, give me a router and router will be coming from Express Dot.

06:07.020 --> 06:10.470
And again, this is a capital root for a router and worse.

06:10.470 --> 06:13.440
And the very first thing we always do is export this router.

06:13.440 --> 06:15.720
I have seen people forgetting quite a lot about it.

06:15.720 --> 06:19.830
That's why I recommend everybody that as soon as you create the router, go ahead and export that and

06:19.830 --> 06:21.330
do rest of the things later on.

06:21.600 --> 06:22.380
So there we go.

06:22.380 --> 06:25.770
We have now this router now coming on.

06:25.800 --> 06:29.640
We need to create a route where we can use that sign up method that we have worked on.

06:29.640 --> 06:30.900
So first let's bring up that.

06:30.900 --> 06:35.670
So we're going to go ahead and say, hey, I want to bring some methods and these methods will be coming

06:35.670 --> 06:43.470
up from let's go ahead and say, hey, I want to go ahead and work on require from one directory back.

06:43.470 --> 06:49.380
We have controllers and inside that we have this user controller.

06:49.410 --> 06:49.820
Okay.

06:50.010 --> 06:53.640
So what is the one method that we are exporting right now, which is just the sign ups?

06:53.640 --> 06:57.180
So as soon as I say this, they should actually suggest me hopefully in theory.

06:57.180 --> 07:02.220
So if I go ahead and say sign up, okay, now let's create a route based on this signup.

07:02.220 --> 07:09.720
So router dot route and we are going to say that what route you want to have, I will say that this

07:09.720 --> 07:11.550
is going to be simply sign up.

07:11.550 --> 07:12.960
That's basically it.

07:12.960 --> 07:16.140
And as soon as the sign up comes up, there should be a verb there.

07:16.140 --> 07:18.780
So that verb in this case is going to be post again.

07:18.780 --> 07:19.740
The data is coming up.

07:19.740 --> 07:24.390
We are putting that data in the database as well so it makes sense to have a post route.

07:24.390 --> 07:27.330
So what is the functionality which will handle this post route?

07:27.330 --> 07:29.760
Simply the sign up, that's it.

07:29.760 --> 07:33.360
That's how you create the routes and we'll be creating a lot more in the future.

07:33.360 --> 07:34.650
But there is one more thing.

07:34.650 --> 07:40.320
This router is not yet being imported to dogs, so this needs to be done here as well.

07:40.530 --> 07:42.600
So let's go ahead and work on with that.

07:42.600 --> 07:44.970
So this is where we import our all of our routes.

07:44.970 --> 07:49.560
So we're going to go ahead and say that, hey, I want to bring up a user.

07:49.770 --> 07:51.510
And that will require.

07:53.370 --> 07:54.930
Let's go into.

07:56.780 --> 07:58.820
Come on, let's go into roots.

07:58.910 --> 07:59.300
Come on.

07:59.300 --> 08:00.080
Suggest me.

08:01.290 --> 08:01.950
There we go.

08:01.950 --> 08:03.930
And inside that, we have this user.

08:04.710 --> 08:07.610
Now, all I have to do is inside my router middleware.

08:07.620 --> 08:12.090
I'm going to make a copy of this and I will say that, hey, this will be handled by the user.

08:12.090 --> 08:17.370
So now what will happen if somebody visits local host, colon, whatever the port you are having in

08:17.370 --> 08:25.320
my case, 4000 so localhost slash column 4000 slash API slash V1 slash sign up, then he'll be able

08:25.320 --> 08:26.110
to see that.

08:26.130 --> 08:31.050
Now, just to make sure that we actually test this out nicely, I'm going to go ahead for a moment.

08:31.050 --> 08:33.090
I'm going to turn this up into a git.

08:33.270 --> 08:36.120
And here I'm going to go ahead and simply send a response.

08:36.120 --> 08:38.100
So I'm going to say Rez Dot send.

08:39.310 --> 08:45.250
And I'm going to go ahead and send up a simple signup route so that we can at least test out these things.

08:45.280 --> 08:48.040
Now for testing, we're going to be firing up the postman.

08:48.040 --> 08:53.410
So let's go ahead and bring up the postman, because it makes sense now to have this postman up and

08:53.410 --> 08:54.280
running for us.

08:55.910 --> 08:56.180
Okay.

08:56.180 --> 08:58.700
So I will create a new collection and everything up here.

08:58.700 --> 09:00.980
So let's go ahead and first create an environment.

09:01.920 --> 09:06.840
So let's go ahead and create an environment called this as t shirt store.

09:08.020 --> 09:10.150
And inside this, let's add a variable.

09:10.210 --> 09:12.670
Let's call this one as domain.

09:12.670 --> 09:21.730
And the value is going to be http colon slash slash local host slash API slash V one.

09:21.730 --> 09:25.750
So this is like the basic of all the stuff that I have.

09:26.080 --> 09:27.700
And after that, I'll be putting it up.

09:27.710 --> 09:32.290
So I think this is all what we are going to have and.

09:32.990 --> 09:35.240
Let's place it into t shirt store.

09:36.050 --> 09:36.500
Okay.

09:36.500 --> 09:37.790
We can save that now.

09:38.600 --> 09:43.880
Now, let's go ahead and create a new collection of the APIs, because this is important and sometimes

09:43.880 --> 09:45.780
we need to place that into separate folder.

09:45.800 --> 09:46.790
It's a good thing.

09:46.790 --> 09:49.250
So we're going to call this 1st shirt.

09:51.400 --> 09:52.270
Store.

09:53.570 --> 09:57.020
And we are going to be changing the environment to the t shirt store.

09:57.050 --> 09:58.310
That is fantastic.

09:58.340 --> 10:00.560
Now, let's go ahead and close all of these guys.

10:00.590 --> 10:02.330
No, I don't want to save this.

10:02.870 --> 10:09.770
And inside this one, we are going to create a new folder, add a folder, and I'm going to call this

10:09.770 --> 10:11.140
one as simply user.

10:11.150 --> 10:14.510
So all the requests that are based on the user will actually go up here.

10:14.510 --> 10:16.930
So I'm going to go ahead and say add request.

10:16.940 --> 10:17.750
There we go.

10:17.750 --> 10:20.210
And this one is going to be for sign up.

10:21.800 --> 10:22.610
For sign up.

10:22.610 --> 10:26.270
As of now, we have get, but we are going to definitely modify it a little bit.

10:26.270 --> 10:29.720
So we're going to go ahead and say, hey, I want to have.

10:31.400 --> 10:32.840
This domain.

10:33.200 --> 10:38.660
And after that domain, we are going to go ahead and simply say, slash, sign up.

10:39.890 --> 10:45.140
Now let's go ahead and hit a send on this one and it says, hey, the connection was refused.

10:45.710 --> 10:47.480
Did I set it up correctly?

10:49.280 --> 10:49.880
Let's go ahead.

10:49.880 --> 10:50.780
Did we got a request?

10:50.810 --> 10:51.020
No.

10:51.020 --> 10:51.890
Our server is running.

10:51.890 --> 10:53.300
Let's go ahead and quickly check that.

10:53.300 --> 10:55.160
What is messing up in this one?

10:56.680 --> 10:57.270
My bad.

10:57.280 --> 10:59.920
I forgot to just add a port number after the localhost.

10:59.920 --> 11:04.600
So I go back again into the environment and again it sometimes takes a little bit while to actually

11:04.600 --> 11:05.290
set up the environment.

11:05.290 --> 11:06.960
Once you set it up, it's all great.

11:06.970 --> 11:11.650
We'll be saying 4000 slash API slash, let's go ahead and save this one.

11:11.650 --> 11:13.030
So variable is now saved.

11:13.030 --> 11:16.990
And that's a beauty about having an environment variable that if you have like so many of the requests

11:16.990 --> 11:18.760
going on, suddenly you decide to change that.

11:18.760 --> 11:20.180
Now it's 5000 port.

11:20.230 --> 11:23.190
You can just change it in one place and it just works everywhere.

11:23.200 --> 11:24.610
Let's go ahead and send it up.

11:24.610 --> 11:28.600
It still says there are some issues, so it looks like there are some more of these issues.

11:28.960 --> 11:31.750
Let me go ahead and try to figure them out one more time.

11:32.440 --> 11:32.860
Okay.

11:32.860 --> 11:38.200
So it turned out that when I just don't use the variable, I just simply send local host 4000 slash

11:38.200 --> 11:39.550
API slash v one.

11:39.550 --> 11:41.410
The sign up route actually works fine.

11:41.410 --> 11:44.110
So probably there is something which I'm not able to see.

11:44.110 --> 11:48.700
I just want to convert this much of the thing slash tilde v one into available.

11:48.700 --> 11:50.470
So let's go ahead and copy that.

11:50.470 --> 11:53.440
And let me just try to create another variable.

11:53.590 --> 11:56.200
Probably I'm missing something which I'm not able to figure it out.

11:56.200 --> 11:57.220
But again, no issues.

11:57.220 --> 12:01.360
We can just go ahead into environment, click on the next and we want to create this one.

12:01.360 --> 12:04.780
So I'm going to call this one as t shirt store.

12:05.110 --> 12:11.470
And this is a new environment for T Shirt store itself and this variable will be available here.

12:11.470 --> 12:14.590
I'm going to call this one as simply my domain.

12:14.590 --> 12:16.360
Maybe there's something which I'm missing.

12:16.360 --> 12:20.170
So initial value and the current value is going to be same.

12:20.170 --> 12:24.400
Hopefully, let's save this one and let's try to get another route up here.

12:24.400 --> 12:30.610
So let's go ahead and close this one and send another request to get same get request.

12:30.730 --> 12:34.930
And we'll be saying that, hey, I want to use something like my domain.

12:35.230 --> 12:40.000
And after that slash sign up, let's go ahead and see if we are able to see something.

12:40.360 --> 12:40.560
Okay.

12:40.630 --> 12:43.450
It says I cannot get the sign up.

12:43.450 --> 12:45.320
Probably I misspelled that.

12:45.340 --> 12:47.170
Okay, sign up.

12:48.040 --> 12:49.570
And now we get this sign up route.

12:49.570 --> 12:53.530
So probably there is something which I was missing and I was not able to locate that.

12:53.530 --> 12:55.240
So that is totally fine.

12:55.240 --> 12:58.420
I'm going to go ahead and close this one because I don't need this.

12:58.420 --> 13:00.130
This is fine as my domain.

13:00.130 --> 13:02.110
I'm going to go ahead and save this one.

13:02.110 --> 13:06.310
So this one will go into the t shirt store and inside the user itself.

13:06.310 --> 13:12.340
So setting this up is always going to be helpful and we don't need this my sign up route now, so I'm

13:12.340 --> 13:14.500
going to go ahead and remove the above one.

13:14.500 --> 13:16.900
So let's go ahead and delete this, delete that.

13:17.140 --> 13:21.580
Now also, I'll select this route up here and we're going to rename this one again.

13:21.580 --> 13:24.610
Renaming is super easy, so I'm going to go ahead and rename this one.

13:24.610 --> 13:26.800
I'm going to call this one as simply sign up.

13:26.980 --> 13:28.330
There we go again.

13:28.330 --> 13:30.880
Renaming doesn't mean where you are sending the request itself.

13:30.880 --> 13:32.470
It doesn't really bother that part.

13:32.470 --> 13:34.210
So we're going to call this one as my domain.

13:34.210 --> 13:36.250
Again, it's really the same again.

13:36.250 --> 13:39.460
I prefer that using the variable makes life a little bit easier.

13:39.460 --> 13:44.680
In case you don't want to, you can simply go ahead and use HTTP colon 4000 slash API slash V one.

13:44.680 --> 13:49.480
So this is the sign up route and we can also verify that by using our same dummy route.

13:49.480 --> 13:50.620
So this is what it is.

13:50.710 --> 13:55.600
Now I'll check back again into sign up and there we go.

13:55.600 --> 14:00.370
Now in definitely in the reality, we'll be changing it into a post request, so I'll just save it up

14:00.370 --> 14:00.610
here.

14:00.610 --> 14:02.260
Notice the request changes up here.

14:02.260 --> 14:04.060
Let's do all the changes up here as well.

14:04.060 --> 14:10.630
So let's go into user and this is not the get this is actually a post route and sign up will be handling

14:10.630 --> 14:11.200
this one.

14:11.680 --> 14:16.390
So this is all the setup that we got so far in the next video, we'll be actually working on signing

14:16.390 --> 14:17.410
up a real user.

14:17.410 --> 14:19.300
Let's go ahead and catch up in the next video.
