WEBVTT

00:03.730 --> 00:05.440
Hey, did everyone had a share?

00:05.440 --> 00:07.240
And welcome to the new section.

00:07.720 --> 00:13.120
I know this course is really, really long, but whatever you wanted to learn or whatever you wanted

00:13.120 --> 00:15.220
to master, this all is done now.

00:15.220 --> 00:18.550
Or we are onto a system where we are going to work on the order system.

00:18.550 --> 00:21.350
And this is exactly what we have been working so far.

00:21.370 --> 00:27.280
So so far we know how to cross reference into the models itself by using the refs and mongoose dot schema

00:27.280 --> 00:29.020
dot id object id rather.

00:29.020 --> 00:31.210
So this is what we will be doing here as well.

00:31.240 --> 00:36.430
We have also seen in the past that how we can manipulate ratings some of the fields which user don't

00:36.430 --> 00:41.680
directly control, but it is auto calculated, so it's just some mathematical and some of the functions

00:41.680 --> 00:42.600
that run there.

00:42.610 --> 00:44.680
Now here also we are going to work on the same.

00:44.680 --> 00:46.840
Remember, we have to manage the stocks as well.

00:46.840 --> 00:48.850
So stock is nothing, just an inventory.

00:48.850 --> 00:53.320
So as soon as the order is being delivered to the user, that means something has something needs to

00:53.320 --> 00:58.060
be reduced and that is going to be the stock that we are taking from the user while creating the product.

00:58.060 --> 00:58.810
So really simple.

00:58.810 --> 01:00.820
Just like we were manipulating the reviews.

01:00.820 --> 01:03.550
This is how we will be manipulating the stock here.

01:03.550 --> 01:04.840
So really pretty simple.

01:04.990 --> 01:06.700
Apart from that, nothing new.

01:06.700 --> 01:07.930
Nothing new in this one.

01:07.930 --> 01:11.200
So let's go ahead and check out our simple screen up here.

01:11.200 --> 01:12.940
That's how we are managing this one.

01:12.940 --> 01:14.920
So this is the entirety of the models.

01:14.920 --> 01:19.690
I know this is like really a long gone sheet that we have pulled off.

01:19.690 --> 01:21.100
So let me just walk you through.

01:21.100 --> 01:25.540
So this is the payment route that we have already worked with that stripe key Razorpay Key Capture,

01:25.540 --> 01:29.980
Stripe and Capture Razorpay This is the recent one that I added after recording the videos.

01:29.980 --> 01:31.600
This is all what we have worked on.

01:31.600 --> 01:38.050
I've added a simple highlighter on the admin routes up here and the red lines are actually the delete

01:38.050 --> 01:39.100
requests here.

01:39.190 --> 01:44.050
And similarly, these are the routes I forgot to show you these ones, but this is how we actually came

01:44.050 --> 01:44.680
up with that.

01:44.680 --> 01:49.810
So we had the products, we have individual product review review and the reviews.

01:49.810 --> 01:51.520
So reviews all the reviews.

01:51.610 --> 01:56.710
A red line means a simple delete request and a edit request on this one.

01:56.710 --> 02:01.930
And similarly we have got this product, so we need to add the product, get all the products, edit

02:01.930 --> 02:05.410
the product with the special ID that means single product and this one.

02:05.410 --> 02:07.480
And similarly, we'll be working on this one.

02:07.480 --> 02:10.090
So this is the really simple of the route that we have.

02:10.120 --> 02:11.740
We want to create an order.

02:11.740 --> 02:13.690
We want to get an individual order.

02:13.690 --> 02:15.300
We want to get a specific order.

02:15.310 --> 02:15.880
Get my order.

02:15.880 --> 02:22.420
That means just grab the user from request user ID and get all the orders of that particular user itself.

02:22.510 --> 02:27.520
Or we'll be simply filtering that, Hey, get me all the orders whose user is listed as that request

02:27.520 --> 02:29.140
dot user id pretty simple.

02:29.140 --> 02:30.550
And then we have admin.

02:30.550 --> 02:32.020
So he wants to get all the orders.

02:32.020 --> 02:33.400
He wants to update the order.

02:33.400 --> 02:36.190
How much updation facility you want to give, that's up to you.

02:36.190 --> 02:38.890
And we want to obviously allow the admin to delete the order.

02:38.900 --> 02:40.120
So that's pretty much it.

02:40.300 --> 02:45.280
Now further down the road, we will be actually grabbing all of this information that we previously

02:45.280 --> 02:50.200
worked on and we had a lot of discussion about how to actually go ahead and work on with that.

02:50.200 --> 02:56.830
So let me go ahead and copy all of this going back and let's create another model for the orders itself.

02:56.830 --> 03:03.070
So let's go ahead and say new file and this one is going to be order dot JS There we go.

03:04.390 --> 03:06.130
The first thing is we need Mongoose.

03:06.130 --> 03:13.630
So we're going to go ahead and say, Hey, Mongoose, please give me the require as Mongoose.

03:15.600 --> 03:16.620
Come on, suggest me.

03:16.650 --> 03:18.210
No, not going to do that.

03:18.250 --> 03:20.730
Okay, so now we have Mongoose available with us.

03:20.820 --> 03:25.740
Now, I would like to actually paste all of this up here, and I'm going to go ahead and just comment

03:25.740 --> 03:26.060
this out.

03:26.070 --> 03:31.920
This will actually help us to just craft the orders all appear instead of going the sheets back and

03:31.920 --> 03:32.760
forth up here.

03:33.090 --> 03:35.460
So let's go ahead and start working with that.

03:35.460 --> 03:37.460
Let's go ahead and create a simple order schema.

03:37.470 --> 03:42.630
So we're going to go go ahead and call this one as simple order schema.

03:42.990 --> 03:46.080
And that order schema will be created simply from the mongoose.

03:46.080 --> 03:51.480
So let's go ahead and say mongoose dot schema and there we go.

03:51.870 --> 03:55.680
And this reminds me, maybe I have done some mistake in the product.

03:56.870 --> 04:01.670
Okay, so we can actually use the new keyword or we can actually work without the new keyword as well.

04:02.000 --> 04:03.260
However you like to go ahead.

04:03.260 --> 04:07.820
And with that, I will actually use the new keyword here as well to say stay consistent in here.

04:07.940 --> 04:12.830
Now, this reminds me of one more thing, which I was looking up, and I'm pretty sure some of you might

04:12.830 --> 04:16.160
be getting confused in that in case you have previous experience on that.

04:16.160 --> 04:21.620
So sorry for taking this topic really late here, but you might have noticed that we have got a whole

04:21.620 --> 04:23.540
lot of fields going on and working on that.

04:23.540 --> 04:28.580
For example, when I walked you to with the user, we simply say it's mongoose dot schema, dot object

04:28.580 --> 04:33.140
ID, but you are going to notice that a lot of times there is a mongoose dot schema, dot type object

04:33.140 --> 04:33.620
ID.

04:33.710 --> 04:38.240
So yes, I'm pretty aware of the situation because this is a common question that comes around whenever

04:38.240 --> 04:41.200
I take this bootcamp into any of the corporates.

04:41.210 --> 04:46.100
So notice here, this is a StackOverflow that should answer all this question that should I use the

04:46.100 --> 04:50.690
schema type object ID or you should use the schema dot object ID when defining.

04:50.690 --> 04:54.440
And the very first answer actually sums it all up that it doesn't matter.

04:54.440 --> 04:55.820
Both are exactly same.

04:55.820 --> 05:00.830
If you are actually using the console log, you'll see that they actually gives you the exact same result.

05:00.830 --> 05:06.290
But there is further down the road and answer that Hey, I found once an issue that if you want the

05:06.290 --> 05:11.540
backward compatibility, you want to use object schema dot object ID in case you want to follow the

05:11.540 --> 05:14.510
newer convention, then you can go ahead and use the types dot object id.

05:14.510 --> 05:17.330
So again they exactly means the same.

05:17.480 --> 05:19.820
It's up to you that what you really want to grab there.

05:20.570 --> 05:27.350
So inside this order ID in fact at the very end of it I'll just go ahead and some put some ref link.

05:27.350 --> 05:32.600
So let's just say ref link so that later on in case you want to, you can go ahead and read this one

05:32.600 --> 05:33.020
to.

05:33.110 --> 05:35.270
So I'll just add this one for your reference.

05:36.710 --> 05:40.820
Moving on, let's go up here and inside this order schema.

05:40.820 --> 05:44.000
Let's go ahead and start working with how the order is going to be placed.

05:44.000 --> 05:45.680
This is going to be a really long one.

05:45.800 --> 05:48.110
So the first thing that we need is the shipping info.

05:48.140 --> 05:51.110
Let's go ahead and copy that and bring this one here.

05:51.110 --> 05:54.470
So the shipping info, obviously, this is going to be an object.

05:54.470 --> 05:58.100
And inside the shipping info, we need a lot of information from the user.

05:58.190 --> 06:00.890
So first we are going to say that, hey, give me your address.

06:00.890 --> 06:05.090
And sometimes people take address, line one, address, line two, totally up to you.

06:05.180 --> 06:11.600
The type is obviously going to be string and we are going to say that this is a required field, otherwise

06:11.600 --> 06:13.580
how we are going to ship the order itself.

06:13.580 --> 06:14.570
So there we go.

06:14.990 --> 06:15.320
Okay.

06:15.320 --> 06:20.420
Once I have gone this one, now let's collect some more information inside the same shipping info.

06:20.420 --> 06:23.330
So address is there then we are going to go ahead.

06:23.330 --> 06:26.360
In fact, let me go ahead and make a couple of copies of it.

06:27.950 --> 06:31.670
Now, once the address is done, we obviously want to take city as well.

06:31.880 --> 06:35.360
Maybe you want to take address line two or also that is totally fine.

06:35.360 --> 06:42.890
Then we need to take phone number, phone number and let's go ahead and make a couple of more copies

06:42.890 --> 06:43.520
of it.

06:44.150 --> 06:50.000
So once I have the phone number, I have city, I will take probably state as well.

06:50.030 --> 06:53.780
Or we can take a postal code.

06:54.470 --> 06:56.180
You might want to take state as well.

06:56.180 --> 06:59.720
So let's go ahead and take state as well as much information as you grab.

06:59.720 --> 07:00.800
That's always good.

07:00.800 --> 07:03.500
And we're going to go ahead and take country finally.

07:04.280 --> 07:04.440
Okay.

07:04.550 --> 07:08.360
So all these information are absolutely necessary and they are required.

07:08.390 --> 07:09.920
Let's go ahead and shrink it down.

07:09.920 --> 07:12.110
So this is the shipping info that we need.

07:12.410 --> 07:13.370
Okay, let's come back.

07:13.370 --> 07:14.540
And what else do we need?

07:14.540 --> 07:19.250
After the shipping info, we're going to go ahead and say that we need a user.

07:19.250 --> 07:21.320
So who is placing this order?

07:21.560 --> 07:26.540
Let's go ahead and say that this is going to be the user who is placing the order just like this.

07:27.830 --> 07:29.480
What is the type of the user?

07:29.480 --> 07:36.860
The type of the user is actually mongoose dot schema dot object ID.

07:36.860 --> 07:39.380
Again, you can use optionally types here.

07:39.380 --> 07:49.610
So you can go ahead and say, hey, I can go ahead and say mongoose dot schema, dot type's.

07:50.180 --> 07:55.550
Remember it is not type it is actually types object ID, there we go.

07:55.550 --> 08:02.120
And you can actually optionally go ahead and use this one and moving further once we have this, then

08:02.120 --> 08:03.800
we have to provide the reps as well.

08:03.800 --> 08:08.420
So from where I should take the reference, you should take the reference from the user model itself.

08:08.450 --> 08:09.350
Is it required?

08:09.350 --> 08:10.190
Yes, 100%.

08:10.190 --> 08:11.240
This is required.

08:12.870 --> 08:13.570
There we go.

08:13.590 --> 08:14.130
True.

08:14.910 --> 08:15.390
Okay.

08:16.710 --> 08:21.360
So once we have this user now, let's go ahead and take care of this order items because this is, again,

08:21.360 --> 08:23.730
a mammoth of the object itself.

08:23.730 --> 08:29.550
And this one is going to be an array of object because order item can have two t shirts or two types

08:29.550 --> 08:34.140
of t shirt, maybe three products each, each of them having many variety.

08:34.140 --> 08:37.590
So this is how important it is and make sure you keep them as an array.

08:37.800 --> 08:42.510
So let's go ahead and say this is going to be an order item, this is going to be an array, and inside

08:42.510 --> 08:44.520
the array will be having multiple of the objects.

08:44.520 --> 08:49.740
So what, how the one object itself is going to look like we'll be just adding these information, name,

08:49.740 --> 08:54.510
quantity images, just the one image, actually the price and the product itself.

08:54.510 --> 08:55.740
What is the product here?

08:55.740 --> 08:59.220
Let's go ahead and say, hey, I would like to first add the name here.

08:59.940 --> 09:01.560
So what is the name of the product?

09:01.560 --> 09:05.190
We can actually grab it from the front end that whatever the product you are calling in.

09:05.190 --> 09:12.240
So let's go ahead and say, hey, this one is going to be type of string and this one is required also.

09:12.900 --> 09:16.890
Otherwise, how would we know that what item to ship a ship to the user?

09:17.550 --> 09:25.170
Okay, let's go ahead and grab a name then we have got one, two, three, four, five.

09:25.320 --> 09:28.230
So one, is there two, three, four, five.

09:28.230 --> 09:30.150
Okay, now moving on.

09:30.150 --> 09:32.100
The next one is quantity.

09:32.100 --> 09:36.270
So let's go ahead and see quantity.

09:36.270 --> 09:39.210
The quantity is obviously going to be type of number.

09:39.210 --> 09:40.560
This quantity represents that.

09:40.560 --> 09:45.390
Let's just say there is a pro order t shirt and I want five t shirts maybe for some reason.

09:45.390 --> 09:47.040
So that is why the number is there.

09:47.250 --> 09:52.050
Then the image this says you can skip this part if you in case you don't want to handle the images.

09:52.050 --> 09:53.430
But this is all okay.

09:53.460 --> 09:57.030
We are going to have a type of string and we're going to require true.

09:57.090 --> 09:59.490
Now what you're going to inject further down the road.

09:59.490 --> 10:02.340
You don't need to have the public ID or anything of the image.

10:02.340 --> 10:05.550
We will be just injecting the security URL in this one and that's it.

10:05.550 --> 10:07.470
We'll call it as a day off here.

10:07.740 --> 10:11.430
Now, after the image, we have got the price, of course.

10:12.030 --> 10:13.050
So there we go.

10:13.050 --> 10:17.130
So price the price is going to be number.

10:19.040 --> 10:24.280
Now this is going to be the price of let's just say you are ordering pro order t shirt.

10:24.290 --> 10:26.290
You have ordered five of these t shirts.

10:26.300 --> 10:32.240
So this price is going to be 299 or whatever the t shirt price is, let's just say ₹500.

10:32.240 --> 10:33.860
So 500 multiply by five.

10:33.860 --> 10:37.250
So this is the price that will be going on for that individual product.

10:37.730 --> 10:41.360
And then finally at the end, we are going to have a product.

10:41.840 --> 10:49.220
Now this product again, we can borrow some code from here, actually copy that because this is a product

10:49.220 --> 10:50.660
and we need to have a reference here.

10:50.660 --> 10:55.190
So we're going to say, hey, mongoose, dot schema, dot object ID is going to be there.

10:55.190 --> 11:01.400
And the reference that you need to take is actually from the product and required is true and that's

11:01.400 --> 11:01.880
pretty much it.

11:01.880 --> 11:03.020
That's all what we got.

11:03.290 --> 11:03.790
Okay.

11:04.310 --> 11:07.670
So this is the behemoth of the data that we need to manage up here.

11:07.670 --> 11:11.350
And once this is all done, this is all like really the biggest of one.

11:11.360 --> 11:13.700
Let's go ahead and work on with the rest of them.

11:13.700 --> 11:15.530
Let me go ahead and squeeze this.

11:15.530 --> 11:17.780
There we go and put up a comma.

11:17.780 --> 11:18.560
There we go.

11:18.590 --> 11:20.330
Now, what else we got up here.

11:20.690 --> 11:22.310
So this order item is all done.

11:22.790 --> 11:24.050
We got user done.

11:24.050 --> 11:26.150
Now we need to take care of the payment info.

11:26.180 --> 11:31.610
Now the reason payment info could be directly a string itself, but I would love to create an object

11:31.610 --> 11:37.100
into this one because later on maybe it comes up that, hey, I want to take more information inside

11:37.100 --> 11:41.960
this payment info, maybe want to create a separate dashboard for the admin, for all the payment information,

11:41.960 --> 11:46.910
cards, user, and all the details that I can probably grab from either stripe or razorpay.

11:46.910 --> 11:49.940
So we're going to go ahead and say, Hey, this is going to be a type of string.

11:49.940 --> 11:50.390
That's it.

11:50.390 --> 11:51.470
That's all for now.

11:51.470 --> 11:54.560
But this is all kept as for the future usage.

11:55.040 --> 11:56.540
Okay, now moving on.

11:57.050 --> 12:02.360
We want to have as payment info is there, then we have got a whole lot of amounts.

12:02.360 --> 12:08.540
So let's go ahead and say this is a text amount, so let's go ahead and grab the text amount.

12:08.810 --> 12:09.830
Scroll there.

12:09.830 --> 12:10.460
There we go.

12:10.640 --> 12:12.980
Now how does the text amount looks like?

12:12.980 --> 12:13.580
So there we go.

12:13.580 --> 12:15.620
We are going to create an object on this one.

12:15.980 --> 12:23.840
So the type is obviously going to be number in the text amount and we are going to have required as

12:23.840 --> 12:24.200
well.

12:24.200 --> 12:25.760
So this is required.

12:26.420 --> 12:27.050
True.

12:27.050 --> 12:30.050
So somebody needs to send me this text amount.

12:30.050 --> 12:35.240
Let's go ahead and grab a copy of this because we will be having a very similar field solve this like

12:35.240 --> 12:35.600
this.

12:35.600 --> 12:37.070
So two copies of this.

12:37.310 --> 12:39.830
So after the text amount, we have shipping amount.

12:39.830 --> 12:41.480
Let's go ahead and in fact, copy this.

12:41.480 --> 12:47.300
Now I'll write that this one is going to be shipping amount.

12:47.810 --> 12:51.530
And after the shipping amount, we have total amount.

12:53.840 --> 12:57.560
I can come up here and say total amount.

12:58.520 --> 13:00.160
Okay, so this is all done.

13:00.170 --> 13:03.920
Now we have another field which is order status.

13:03.920 --> 13:07.640
So copy that and let's go ahead and see that.

13:07.970 --> 13:10.770
So how does this order status is going to look like?

13:10.790 --> 13:12.980
Now, this order status is going to be pretty simple.

13:12.980 --> 13:16.460
It is going to be a simple string, which is going to be default as processing.

13:16.460 --> 13:19.040
And later on you can allow the user to change it.

13:19.040 --> 13:20.570
In fact, you can add an enum here.

13:20.570 --> 13:22.580
That would be also fine, but I'm not going to do it.

13:22.580 --> 13:24.290
I'll leave that as an exercise for you.

13:24.470 --> 13:26.600
So type is going to be string.

13:26.990 --> 13:27.800
There we go.

13:28.820 --> 13:29.480
Come on.

13:30.520 --> 13:38.550
A string and then we are going to have a required of true and we we'll also put up a default value.

13:38.550 --> 13:40.350
So the default is going to be.

13:41.810 --> 13:42.620
Processing.

13:42.620 --> 13:44.300
I like to keep everything as lowercase.

13:44.300 --> 13:49.550
If I need a per case or a capitalized case in the front end, I can do that from the JavaScript manipulation

13:49.550 --> 13:50.150
later on.

13:50.150 --> 13:50.960
Not here.

13:51.560 --> 13:54.560
I like consistency of the lowercase all the time up here.

13:55.430 --> 14:00.450
Further down the road we have another which is delivered at so.

14:00.470 --> 14:04.310
Copy that and let's go ahead and paste it up here, deliver that.

14:04.580 --> 14:06.110
So this is a really simple field.

14:06.110 --> 14:08.000
All it takes is a type of date.

14:08.000 --> 14:10.100
So let's go ahead and give it a date.

14:10.100 --> 14:16.460
Somebody needs to pass me the date of whenever this is being this order is being processed as delivered.

14:16.460 --> 14:19.520
As soon as that we are going to just pass on a date field and that's it.

14:19.880 --> 14:24.020
And after the end of it, we are going to go ahead and have a simple created at.

14:24.020 --> 14:29.090
So let's go ahead and copy that and let's go ahead and check it out.

14:29.930 --> 14:31.790
Create that again, really simple.

14:31.790 --> 14:33.230
We have done this one so many times.

14:33.230 --> 14:34.040
Shouldn't be a big deal.

14:34.040 --> 14:39.980
This is a type date and the default is date now always date dot now.

14:39.980 --> 14:40.640
There we go.

14:41.440 --> 14:44.300
Okay, so now this seems okay.

14:44.300 --> 14:45.380
Let me take a close look.

14:45.380 --> 14:50.320
If I haven't missed anything or there is something more that we can actually add or is it all okay,

14:50.620 --> 14:51.010
okay.

14:51.230 --> 14:52.700
So this seems all okay.

14:52.760 --> 14:56.690
I have gone through again with the list that we walked in up here.

14:56.690 --> 14:59.630
So this is what I have been stating for a while.

14:59.630 --> 15:03.620
So it looks like everything is all in control and everything is all being done.

15:03.770 --> 15:05.450
Okay, let's go ahead and shrink this up.

15:05.450 --> 15:06.050
So there we go.

15:06.080 --> 15:08.420
This looks okay now let's go ahead and export this.

15:08.420 --> 15:16.880
So simply, we are going to go ahead and say module dot exports and we're going to export using mongoose

15:16.910 --> 15:18.980
dot model.

15:18.980 --> 15:22.400
And this one is going to take order again in the database.

15:22.400 --> 15:24.440
It will be created as orders all lowercase.

15:24.440 --> 15:27.830
I know that and this will be taken up as order schema.

15:27.830 --> 15:28.670
So there we go.

15:28.700 --> 15:34.490
Now, in theory at least, our model is all done and is all ready to work on whether I would like to

15:34.490 --> 15:39.920
shrink all of this, because I will need to actually see this quite a lot when I'll be creating the

15:39.920 --> 15:45.260
order, because there is a lot of information that is coming in and we are manipulating only a handful

15:45.260 --> 15:46.490
of information in this case.

15:46.490 --> 15:47.240
So there we go.

15:47.240 --> 15:49.490
So this is all the data that we are collecting.

15:49.490 --> 15:53.120
I know a lot of them are objects and this is too much of the data to process.

15:53.360 --> 15:54.410
Okay, so that's it.

15:54.410 --> 15:58.430
And let's go ahead and catch up in the next video and create controllers for this order.
