Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,060 --> 00:00:04,650
And now to finish the section, let's now very quickly
2
00:00:04,650 --> 00:00:06,893
finish the bookings API.
3
00:00:08,700 --> 00:00:11,970
And once more, I actually want you to practice your skills
4
00:00:11,970 --> 00:00:12,950
at this point,
5
00:00:12,950 --> 00:00:16,030
and so basically implement all the missing endpoints
6
00:00:16,030 --> 00:00:17,860
completely on your own here.
7
00:00:17,860 --> 00:00:20,350
So, really adding adding all the CRUD operations.
8
00:00:20,350 --> 00:00:24,180
So, creating, getting, reading and updating bookings.
9
00:00:24,180 --> 00:00:26,873
So pause the video now and I see you in a second.
10
00:00:31,010 --> 00:00:35,570
Okay, so let me start here by using the factory
11
00:00:35,570 --> 00:00:38,480
that we already have in order to create
12
00:00:38,480 --> 00:00:40,373
all these five handlers.
13
00:00:43,660 --> 00:00:46,730
So, create booking is done using
14
00:00:46,730 --> 00:00:48,413
factory.createOne
15
00:00:51,150 --> 00:00:52,623
and passing in the booking.
16
00:00:53,490 --> 00:00:56,203
And now, let me duplicate this five times.
17
00:00:59,170 --> 00:01:00,383
So, get booking,
18
00:01:02,666 --> 00:01:03,916
getAllBookings,
19
00:01:07,370 --> 00:01:08,600
updateBooking,
20
00:01:08,600 --> 00:01:09,433
and
21
00:01:10,281 --> 00:01:11,570
deleteBooking.
22
00:01:11,570 --> 00:01:12,763
And now here the same.
23
00:01:15,730 --> 00:01:18,323
Get all, or actually get one.
24
00:01:21,350 --> 00:01:23,410
Then here it's getAll.
25
00:01:23,410 --> 00:01:24,787
Here it's updateOne.
26
00:01:26,425 --> 00:01:28,340
And deleteOne.
27
00:01:28,340 --> 00:01:30,140
So, very easy.
28
00:01:30,140 --> 00:01:32,653
Now, moving on to the routes.
29
00:01:36,340 --> 00:01:38,253
So router.route,
30
00:01:39,300 --> 00:01:42,990
and so without the booking's id, we have as always
31
00:01:42,990 --> 00:01:45,323
getting all and creating a new one,
32
00:01:47,050 --> 00:01:47,883
right.
33
00:01:49,210 --> 00:01:52,480
Now, all of these will actually be protected
34
00:01:52,480 --> 00:01:56,580
and also only restricted to administrators and lead guides.
35
00:01:56,580 --> 00:02:00,670
And so actually let me do that outside here of this handler.
36
00:02:00,670 --> 00:02:02,310
And so here, all we will have
37
00:02:02,310 --> 00:02:04,823
is really bookingController.getAllBookings.
38
00:02:08,009 --> 00:02:10,440
And so just like before, I will actually use
39
00:02:10,440 --> 00:02:13,113
the protect middleware completely outside.
40
00:02:16,120 --> 00:02:18,677
So router.use(authController.protect).
41
00:02:24,340 --> 00:02:26,363
Then I can remove it from here,
42
00:02:29,840 --> 00:02:33,160
and then the next routes and all of them
43
00:02:33,160 --> 00:02:36,880
will only be accessible to administrator and lead guides.
44
00:02:36,880 --> 00:02:37,900
Now right,
45
00:02:37,900 --> 00:02:40,750
so for a lead guide to basically know which tourists
46
00:02:40,750 --> 00:02:43,450
have been booked, and for an admin, well,
47
00:02:43,450 --> 00:02:47,340
to kind of update or delete tourists if necessary.
48
00:02:47,340 --> 00:02:48,620
All right.
49
00:02:48,620 --> 00:02:51,860
So that's authController.restrictTo
50
00:02:54,360 --> 00:02:55,193
admin
51
00:02:58,140 --> 00:02:59,183
and lead guide.
52
00:03:02,720 --> 00:03:04,460
So .get
53
00:03:04,460 --> 00:03:06,710
and .post
54
00:03:06,710 --> 00:03:07,633
as well,
55
00:03:08,640 --> 00:03:10,790
and that one is then createBooking.
56
00:03:16,490 --> 00:03:17,420
Now right.
57
00:03:17,420 --> 00:03:20,103
And now the routes with the id.
58
00:03:23,800 --> 00:03:27,310
So, as always, in all our other resources,
59
00:03:27,310 --> 00:03:28,653
we did exactly the same.
60
00:03:30,620 --> 00:03:32,570
So that's bookingController.getBooking,
61
00:03:38,550 --> 00:03:43,550
then we have patch, which is for updating,
62
00:03:44,260 --> 00:03:45,750
so updateBooking.
63
00:03:48,810 --> 00:03:50,880
And finally, we have .delete
64
00:03:51,820 --> 00:03:55,803
for bookingController.deleteBooking.
65
00:03:57,370 --> 00:04:01,210
So, very easy that's our bookings API.
66
00:04:01,210 --> 00:04:04,190
And so just to test, let's actually just add
67
00:04:04,190 --> 00:04:07,853
the getAllBookings and getBooking to Postman.
68
00:04:09,570 --> 00:04:12,380
All right, so I'm not really interested
69
00:04:12,380 --> 00:04:14,570
in adding all these endpoints here.
70
00:04:14,570 --> 00:04:16,673
That takes a bit too much time.
71
00:04:18,510 --> 00:04:19,343
All right.
72
00:04:20,899 --> 00:04:22,550
So let me just try with this one.
73
00:04:33,614 --> 00:04:34,980
So that's bookings,
74
00:04:34,980 --> 00:04:37,950
and so that should actually already be enough.
75
00:04:37,950 --> 00:04:40,453
Or no, we need the authorization as well.
76
00:04:41,930 --> 00:04:44,443
And so let's quickly login as an admin.
77
00:04:49,548 --> 00:04:51,240
So that's I believe
78
00:04:51,240 --> 00:04:55,463
admin@natours.io.
79
00:04:58,910 --> 00:05:00,640
Yep, that's correct.
80
00:05:00,640 --> 00:05:03,660
And so, let's see.
81
00:05:03,660 --> 00:05:05,820
And here we actually have our booking.
82
00:05:05,820 --> 00:05:07,293
And right now it's only one,
83
00:05:09,010 --> 00:05:10,280
but that works.
84
00:05:10,280 --> 00:05:13,400
And you see that actually the tour gets populated here
85
00:05:13,400 --> 00:05:15,923
which in turn gets populated with the guides,
86
00:05:17,030 --> 00:05:20,430
but as we said earlier that's not a big deal in this case,
87
00:05:20,430 --> 00:05:23,450
because the square here is not going to be done
88
00:05:23,450 --> 00:05:24,433
so many times.
89
00:05:25,390 --> 00:05:28,300
Now right, also the user is populated,
90
00:05:28,300 --> 00:05:30,563
and then of course the prize.
91
00:05:32,070 --> 00:05:34,810
Now right, let's quickly save this here
92
00:05:35,990 --> 00:05:38,630
and actually not into a new collection,
93
00:05:38,630 --> 00:05:43,630
but here I want to create a new folder for bookings.
94
00:05:45,900 --> 00:05:47,230
So get all
95
00:05:49,890 --> 00:05:50,833
bookings.
96
00:05:53,520 --> 00:05:54,720
Let's just copy it here.
97
00:06:08,600 --> 00:06:12,053
Now, and of course we need to login here as well.
98
00:06:14,800 --> 00:06:17,893
And so that is get one booking.
99
00:06:22,870 --> 00:06:24,613
Right into,
100
00:06:25,850 --> 00:06:27,470
huh where is that?
101
00:06:27,470 --> 00:06:29,830
I thought I had just created a new folder.
102
00:06:29,830 --> 00:06:30,973
But apparently not.
103
00:06:36,940 --> 00:06:39,143
Okay, so this one is out here.
104
00:06:41,140 --> 00:06:43,590
All right, now again I will not create
105
00:06:43,590 --> 00:06:45,950
these other endpoints here in Postman
106
00:06:45,950 --> 00:06:47,740
because that's not really the point.
107
00:06:47,740 --> 00:06:50,530
You already know how to do that.
108
00:06:50,530 --> 00:06:55,000
Anyway, with this, our API is now actually really finished,
109
00:06:55,000 --> 00:06:58,100
and so all I have now for you is a couple of,
110
00:06:58,100 --> 00:07:01,210
let's say, final considerations and challenges
111
00:07:01,210 --> 00:07:04,410
that you should complete in order to take this project,
112
00:07:04,410 --> 00:07:06,643
and also your skills, even further.
7948
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.