Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
And now to finish the section, let's now very quickly
finish the bookings API.
And once more, I actually want you to practice your skills
at this point,
and so basically implement all the missing endpoints
completely on your own here.
So, really adding adding all the CRUD operations.
So, creating, getting, reading and updating bookings.
So pause the video now and I see you in a second.
Okay, so let me start here by using the factory
that we already have in order to create
all these five handlers.
So, create booking is done using
factory.createOne
and passing in the booking.
And now, let me duplicate this five times.
So, get booking,
getAllBookings,
updateBooking,
and
deleteBooking.
And now here the same.
Get all, or actually get one.
Then here it's getAll.
Here it's updateOne.
And deleteOne.
So, very easy.
Now, moving on to the routes.
So router.route,
and so without the booking's id, we have as always
getting all and creating a new one,
right.
Now, all of these will actually be protected
and also only restricted to administrators and lead guides.
And so actually let me do that outside here of this handler.
And so here, all we will have
is really bookingController.getAllBookings.
And so just like before, I will actually use
the protect middleware completely outside.
So router.use(authController.protect).
Then I can remove it from here,
and then the next routes and all of them
will only be accessible to administrator and lead guides.
Now right,
so for a lead guide to basically know which tourists
have been booked, and for an admin, well,
to kind of update or delete tourists if necessary.
All right.
So that's authController.restrictTo
admin
and lead guide.
So .get
and .post
as well,
and that one is then createBooking.
Now right.
And now the routes with the id.
So, as always, in all our other resources,
we did exactly the same.
So that's bookingController.getBooking,
then we have patch, which is for updating,
so updateBooking.
And finally, we have .delete
for bookingController.deleteBooking.
So, very easy that's our bookings API.
And so just to test, let's actually just add
the getAllBookings and getBooking to Postman.
All right, so I'm not really interested
in adding all these endpoints here.
That takes a bit too much time.
All right.
So let me just try with this one.
So that's bookings,
and so that should actually already be enough.
Or no, we need the authorization as well.
And so let's quickly login as an admin.
So that's I believe
admin@natours.io.
Yep, that's correct.
And so, let's see.
And here we actually have our booking.
And right now it's only one,
but that works.
And you see that actually the tour gets populated here
which in turn gets populated with the guides,
but as we said earlier that's not a big deal in this case,
because the square here is not going to be done
so many times.
Now right, also the user is populated,
and then of course the prize.
Now right, let's quickly save this here
and actually not into a new collection,
but here I want to create a new folder for bookings.
So get all
bookings.
Let's just copy it here.
Now, and of course we need to login here as well.
And so that is get one booking.
Right into,
huh where is that?
I thought I had just created a new folder.
But apparently not.
Okay, so this one is out here.
All right, now again I will not create
these other endpoints here in Postman
because that's not really the point.
You already know how to do that.
Anyway, with this, our API is now actually really finished,
and so all I have now for you is a couple of,
let's say, final considerations and challenges
that you should complete in order to take this project,
and also your skills, even further.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.