Hi everyone!
After we already have a Send request and cancel a request, we will create a method for accept request.
Okay, so let me create.
Accept request.
Right here.
In here we need to mark the request ID okay.
With this string over here.
I will call friend request okay.
And inside the controller I will create the makeup.
Everything over here.
Accept friend request.
And right here will be accept.
Request.
Right.
And we need to vote the friend request.
Over and over here.
The friend request.
And.
Rename the method over here.
We need the current user also.
Right.
And India only.
We need to find the request by this ID over here.
Okay.
And right here.
We need to check.
If we don't have a friend request, I would allow new node file.
Essentially correct.
Node file.
Okay.
And after that we need to check one more thing.
We will need friend request dot state dot.
If it.
Is not appended we will throw the request exception also.
Uh, I will call.
Incorrect.
Only I know.
Okay.
We only accept if the friend request is pending.
Okay.
We cannot accept if this here will be, uh, accept or reject.
Okay.
After that, we need to check one more thing.
Let me show you if the current user dot underscore id.
Different with, uh.
The friend request.
Dot.
Receiver.
We are not on the street.
We will throw the error.
Let me show you why.
My way.
I will throw some error.
The reason?
Because it lights up when I send a request to be okay.
It means right here.
In order to accept the request from A to B, we should log in at B account.
Right?
We should log in with B account to accept the A request.
Right.
And for that reason the current user right here will be the B account okay.
And from here we need to to look up the receiver ID okay.
Receiver array.
In this case first of all will be the base okay.
It means if the base is not.
Are we okay?
We will throw the batch request exception.
Okay.
That's the idea.
And.
Okay, I hope you understand this right here.
I think the best way I can remove the parameter.
Okay.
And we don't need to put any message over here, okay.
We need to automate object in over here.
And after that we will update the status from friend request right here.
Status will be asset and Maxwell with saved into the database.
Okay.
After we saved into the database we should To boost.
The schema over here.
Right over here.
Right.
We sort of right over here.
Let me add a little bit of the file will be an empty array over here.
Okay.
Right here we do.
Let me show you right here.
We need to.
Inject the user.
Right.
Right here.
We already have a user.
So let me open a user survey.
And we need to write a little bit of code.
Right.
Right here I will add right okay I will create a function add friend.
And right here we need to put the user ID the user ID here to find what is the user we want to add three.
Straight.
Right and right.
So.
And right here let me say um we can call.
This dot user model dot update one.
Uh we can put a little bit over here.
Well, I.
Uh, I think we got that.
We are going to update the user ID over here.
And in here we can use add or set operator.
And we need to put the fluoride.
With the fluoride over here.
Right.
So that is we saw with this operator we will.
It's similar Similarly with the boost method from JavaScript.
Okay.
It will find the array in the front row here, and it will perform the boost with the operator.
Okay, that that shot is okay.
I hope you understand.
And right here let me say after here we will append us into the user.
Right.
We need to move that into the user.
Dot user service dot frame one frame.
So this is what user we want to add right.
The user right here we will come from the current user.
Okay.
We can move or we can look at the frame request dot center.
And foreign aid.
Will come from the friend request, not the receiver.
And?
Right here.
Let me call the toString.
And here we will say.
Okay.
And we need to duplicate to the opposite side receiver and sender okay.
So what happened right now we need to add for example the I the I send the request to B and the way.
Will we accept that okay.
It means we want to put the that I will have a friend.
Wait, okay.
And be right here.
We will also have a frame I.
Okay.
That's what we need to do right here.
Firstly, we will add the frame into the sender.
The sender in this case will be the I right.
And we also add the frame into the receiver okay.
In this case will be the base.
And that is okay.
So I hope you understand.
And let's start go to the user controller.
Sorry.
Go to the frame controller accept request.
Let me rename right here.
Okay.
Right now I will send a friend request.
Let me say, after we have ended up with this idea over here and that is the accept request, come with
ID over here.
And let's say, uh, we have a forbidden.
Okay.
Forbidden because you can say right here, we already logged in with the account I.
So for that reason.
We should log in with the receiver over here.
Right.
Let me sign in with this account.
Right away.
Moreover, he.
Said okay.
Let me upload it to the users.
With a friend.
We already have the object with this friend, right?
You can say.
And from this friend over here will fly back to this idea.
Over here.
Okay.
Even right now, we already have a successfully.
Right.
So I think that's it.
Thus will be enough for the video and I will see you in the next one.