All language subtitles for 016 Modelling the Bookings_Downloadly.ir_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

Let's now, really quickly, create the model

for our bookings so that then, in the next video,

we can actually start creating some real bookings.

So, let's close up some of these

files here, also these folders.

Here is the models folder and so booking model.js.

And so this is, of course, gonna be very similar

to what we already did before,

so I will do this pretty quickly.

So as always, we need mongoose,

and we create our booking schema mongoose.Schema,

and now, remember how we said before

that we were going to use paragraph referencing

here on the bookings, so basically keeping a reference

to the tour and also to the user who booked the tour.

So that is very easy.

We did this many times before.

So mongoose.Schema.ObjectId, right?

And then the reference, and this one

is going to point to the tour model.

Then let's also say these are required,

Booking must belong to a Tour.

Now let's just grab this

and create the same thing for a user, okay?

So that's what we just said we were gonna do

keeping a reference of both the tour

that's being purchased and the user who does the purchase.

Then we also want to know the price

at which the purchase actually happened,

and so that's because the price might change

in the future, and so then we would no longer know

how much a certain user paid for a tour.

And so it's important to also have this here

in the booking, so this is going to be a number,

and we also require this,

Booking must have a price.

Next up, let's also create our time stamp createdAt,

which is a date,

and then simply add default

so that we don't have to do anything.

Finally, I also want to create a paid property,

and this one will be automatically set to true,

but this is just in case that, for example,

an administrator wants to create a booking

outside of Stripe.

So, for example, if a customer doesn't have a credit card

and wants to pay directly, like in a store with cash,

or something like that.

And in this case, an administrator might then use

our bookings API in order to basically

manually create a tour, and so that might then be paid

or not yet paid.

So just a very small detail here,

by the thought of that, and thought that it might be

interesting to include that here as well.

But of course, by default, it will be true

so that we don't have to do anything.

Now finally, let's then create a model out of this,

so booking is equal to mongoose.model,

and then, of course, our bookingSchema

and then exporting the whole thing,

is equal to Booking.

Now what we also want to do here

is to populate the tour and the user automatically

whenever there is a query, all right?

So remember how we used to do that

using query middleware.

So, right on the Schema.pre,

and then here or as usual regular expression

and whatever starts with find.

So here next,

and then this.populate,

and let's do it actually automatically

for both the user and the tours.

And in this case that's absolutely no problem

for performance, because there won't be

many calls to the bookings, because only guides and admins

will actually be allowed to do them, all right?

So basically, for a guide to check

was actually booked their tours.

So that's one of the use cases that I see

for this part of the API, okay?

So, again, this query will not happen that often

so we can easily populate all of this

without any problem.

So let's populate also the tour,

but here I actually want to only select the tour name.

So let's say path, tour, and select just the name, okay?

Now here we have some kind of error, all right,

so that should of course be mongoose not moongoose.

So, one more time, ESLint saved us here.

Oh, and actually there are more.

Save it one more time, and now we're good.

So that's actually it.

This is our bookings model

that we can now start using in the next video.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.