- [Instructor] So we've got this Check in form
and we need to actually push that information
over to the database and the reason
I have this error field right here
is because I need to do a little bit
of error checking to make sure
that people can't just come in here
and put in a random URL, whatever they want,
here and create a record in our database.
So I'm only going to allow people to check into meetings
that already exist and they're only going to exist
if a registered user actually creates
the meeting themselves when they're
in this meeting's form.
So I don't want to have sort of random meetings in here.
So what we'll do is modify this so
that it pushes the record of the check in,
but it also verifies that this is actually
an existing meeting.
So we're going to start right here
in this handleCheckIn.
And we'll do an emit,
so this.emit
checkIn, careful with the capitalization,
I notoriously mess that up.
So here we're going to pass along
a record that has the userID
and it's going to get that from
route.params in the userID,
so it's going to get that from the URL.
And we're also going to pass along
the meetingID
and then we'll pass along
the displayName
and the email address from this form.
So now this is going to pass along
the check in event with the proper payload.
Let's go ahead and save this.
And now we need to capture that
in our App.vue component.
Make sure that we have an event here called checkin
and we'll pass it along to a local function called
checkIn, so actually let's make sure we're consistent
with the capitalizations.
Let's see, when we emit the event.
Yeah, we're capitalizing this one.
All right, so now I need to create
this checkIn event.
We've got the add meeting, delete meeting,
and then we're going to create a new one
here called checkIn.
It's going to be a function that takes
in some sort of payload.
And this will be a more comprehensive object.
You saw all the info that we passed along
in the payload, it doesn't just need
to be a simple variable, it can be something more beefy.
All right, so payload.
So I'm going to go and go to the database,
look for the collection called users
and look for the document.
And here I want to use from the payload, the userID
and then go to
the subcollection called meetings
and look for the document
payload.meetingID.
So we're using the information that we got
from the payload to look for the proper document.
So here I could go ahead and insert
the data into the database but I want
to make sure that this is a document
that exists in the database so
that people can only check in to existing meetings.
So what I'll do here is issue a get method.
And do a promise here.
So if you're able to get that document,
then let's do something with that document.
So this is going to be quite a long sort
of query to the database.
So what I'll do is I'll say if the document exists,
and this is just the property that you can ask
if a document currently exists
with these parameters.
That does actually insert the data into our database.
So it's going to be sort of the same thing
that we've done here.
We're going to go to the collection,
payload, meetings, meetingID, right?
So I'll just copy that.
Let's go ahead and indent it a little bit.
Right, so once I get to the meetingID,
then I'm going to start a new collection
inside this meeting
called attendees.
Now if the collection's already there,
it's just going to add a record to that collection
or add a document to that collection.
And then I'll issue an add.
And pass along the data that I want
to add into that record.
So what I want is displayName
payload.displayName
and pass along all the other stuff.
Email.
And I'm also going to add a created at,
just 'cause it's useful to have information
about when a user or when a record
was added into a document.
So you might be doing this all the time
when you insert things, so sort of a nice idea.
So Firebase.firestore.FieldValue
just like we did before and then serverTimestamp.
That is a method.
Right, so, once this is done,
we'll use the promise to make sure that this is complete.
And then we are going to go ahead
and use the router to send people,
so we'll push to send people to the proper page.
So once all this stuff is done,
it's going to send people right now
to the homepage.
What should eventually happen once
we have a meetings page,
then it's going to send people to the proper meeting.
But we don't have that page yet
so I'm just going to push them to the homepage
to make sure that things are working.
All right, so now, if the document doesn't exist,
we're going to create an error
that says, "Sorry, no such meeting".
So we're doing things a little bit differently here.
Remember when we did the log in page
and the register page, we actually did everything
in those pages.
They are self sufficient.
Whereas here, since I'm working with the main component
and this is the component doing things,
I'm going to need to push this error into
the subcomponent because the error's going to,
or it should be displayed in the subcomponent.
So to do that it means that since I'm referring
to something called this error in this component,
it means that I'm going to need
to add an error here
and that is going to need to be passed along
as a prop into our subcomponent.
So we're going to need to put it in here
and then in our checkIn.
We're going to need to read this as a prop.
So we receive that into this component
as a prop and then
we can make sure that this error
is only displayed if that error exists.
So that was a lot of typing.
Hopefully we did everything correctly.
You can see that at least the error
is not showing up.
Let's go ahead and try to send somebody
to the meeting.
So you can see that it cleared everything
but then because everything should have worked,
it sent us back into the Meeting Log homepage.
So that should be it.
Let's check out the database and
there's a lot of meetings here.
But one of them should have this attendees record now.
That's what we just added.
So in attendees, you should see documents
for the new records that we just generated.
So that's how you add new users
and also we did a little bit of error checking
to make sure that somebody doesn't put
in a random URL and then what would happen
is you would actually see new records being added
into our database, not attached to any user,
and it would really cause chaos
by just letting people sign into all kinds
of random meetings.