Hi everyone!
In this video let's try the service to add the reactions into the box.
Okay, well I think with that service we will write that inside the box service.
Okay.
I will not write the reaction into the reaction service okay.
We call this action right here belong to the box right.
I think this is some meaningful than add the logic inside the reaction okay.
I will create a seat will be add reaction.
And what is the deal.
Let's say how we can add a little right here.
Like, imagine what we will send inside here I will duplicate.
And I will create a ask reaction I want.
We will have an URL like that okay.
So that was the reaction inside the body.
Now if you take a look at the schema right here, it has a user boss.
And right here right advertise.
So I will create a boss okay.
We can call the boss ID if you want.
We don't need the user because we will rely on the access token.
We need the type possible to be like us right now with this information.
Let's build the details.
Right here.
And I will export class aggregation.
Later.
We will create a boss ID.
And tie.
With a tie right here.
I reaction tie.
Okay.
And we to add a little bit of Checking validation is Mongo ID.
Okay.
And with that title here is it.
And we will vote for some.
All right.
And you can take a look at the schema right here.
And we arrive from the you know we lost or I think we can separate it into global.
Okay.
Mm.
And in the worst why we can separate does.
Is so here I will create a little box and I will create a log loss.
Us too.
Yes.
Okay.
And right here or.
Actually, this is the dance that.
I will dance with him.
And both.
Over here.
Reaction.
Times.
And reaction time.
And here will be also reaction time in focus.
Okay.
And right here we will have a art reaction.
Little.
And current users.
And what we need to build the logic.
Let me show you what you mean.
Firstly, we need to file the existing.
Existing reaction of the boss.
Why?
The reason we need to find existing.
Because it later.
If.
If we find existing reaction.
Okay.
We need to update with the new.
Reaction.
Sometime, right?
Possible.
Inside the box one.
Let.
Let me show you.
Inside the box one.
The user one will like likes the box one, right?
This is the last box one.
Well, it later if we want to add the reaction into the box one.
Also.
Well, right here, because we already have the reaction of the box one with the user.
So we will update okay.
For example later we can update with the highway inside the box one.
Okay.
So that is that's the idea for the reason we need to find existing Reaction.
If it's not clear, let's write code anyway.
Clear.
Okay.
After we.
Repeat this.
We will bet.
Okay.
If not, is it?
We will create a reaction.
Okay, so let's step by step and write this thing.
Firstly we need to find the existing reaction.
Right.
Well how we can find us.
We need to inject the model after reaction.
Right.
But I don't want us at all.
You can say right here.
Hopefully I will remove the user model.
I don't want to inject one more model again in setup I want to inject the service.
So for that reason in this guy, we will delegate this logic right here into the reaction service.
Okay.
And we will inject the reactions of it.
Okay.
We will not inject in the schema.
Instead we just need to inject the service.
This is very good way.
Okay.
Let me show you what I mean right here.
I will write the code a little bit inside the file.
One right here.
Oh.
Actually, let me create another thing.
We will find.
Uh.
Why is it going?
Okay.
I will create a function like that with Chatlog reaction id.
Okay.
This is clearly the reaction header and the user id.
Okay.
We will get us into this function and we will need to find us.
Actually we just need to return directly over here.
We need to inject the model.
Let's see how we can inject us.
Now let me get my entire constructor over here.
Let's jump over here.
Okay.
And, uh, we need to insert a module also.
Let me copy this thing.
We will remove the user without this dot right now.
Copy this import statement in here.
What does.
Emboss.
Now let's say.
Okay.
Now let's reload it.
We will find why this dot.
Reaction.
Asset model.
Not find one.
Okay.
We will find it by following the reaction ID or actually went to file boss.
Edit my boss over here.
We must add a and the user id.
Okay.
That's the the first one.
And inside the boss service.
I want to inject and use this file sitting over here.
Okay.
In order to inject a service, we just need to call private.
Collection.
So we.
Will serve it over here.
Okay.
We just need to inject us.
And for sure it will get the error.
In order to make this work inside the reaction module, we need to export the current service.
Okay.
The service we want to use in order module will be reaction service.
Right.
And from the the boss of it I will involve entire module.
Now.
Let's see.
Okay.
It will fix the issue.
And right now, I hope you already understand from the Next.js.
Okay.
We already understand that from the Next.js fundamental, right?
It doesn't complicate this at all.
So after we already have a reaction service right here, I will use that.
And we need to boost the boss ID.
Right.
We'll go From here, we can reach up that.
High.
What are these?
And call user.id.
Okay.
We will find the boss over here.
Sorry.
Not find this thing.
Okay.
And right now we will have the existing for the current user.
If the existing exit, we will update with the new reaction.
Okay.
And else we need to create the reaction for the boss.
Okay.
There.
And inside the apron here we have one more condition.
Okay.
For example, if we already like an elixir, we will like that again.
We will want it.
Will not do anything, okay?
Not do anything.
If the new reaction equal without reaction.
Okay.
We need to write one more over here.
So for that reason in this case we need to check the new reaction.
Right.
With the old reaction the old reaction between the existing reaction.
Now right here I will show you if the ties equal with the existing reaction dot tie, we will not do
know anything.
Okay?
We will return directly over here.
And we need to update.
After that, we will update with a new reaction.
So we will write the service again.
Inside here we got the update reaction right.
Um right here.
Let me say update with the new reaction.
Uh.
I will call uh why?
This not present model of the file by ID and that.
Right here we would add it.
And so I will update the time.
Okay.
With the new time.
So I think I will put directly the time over here.
Hi.
So.
With the new video and we need to add a little bit of checking if we don't have reaction.
The reason we not track right here because I want.
We will check inside the boss service.
Okay.
But right now we can feel free to join us.
Okay.
It only depends on your requirement.
Don't take this too much.
And we have a error from the controller.
I think we can remove entirely over here.
Now let's start and remove the use imports.
And over here we will update with the new reaction.
Roy!
Right here.
Way to go.
Why this dot reaction service dot update.
We need to put the reaction ID.
And the new type.
The new type will come from the the type over here.
Okay.
We update with the new reaction and this type right here argument object.
And.
We will it.
So.
Right here I use string is not work right here.
Let me try to convert it to string.
If not I will convert it back to the object ID from here.
Let's give it like this.
And, uh, we need to create the reaction if we don't have the existing reaction.
Right.
So again we need to run it inside the service.
Create over here.
Right now we need to, uh.
Put.
Inside here.
Create reaction.
Little.
Uh.
It will here.
So I think in this case we just need to use the add reaction video.
Okay.
From here.
And let's create us.
The user.
From the sky.
And return reaction dot save method.
Okay.
This will be for create method.
Let's Let me move some stuff over here and, uh, go back to reaction controller and remove this thing
so we don't miss that.
Okay.
It's ah, sweet.
Let's go back and go.
With no, ah, reaction.
Uh, we can go here.
Reaction video.
And the current user mode over here.
Okay.
So.
And, uh, we haven't completed yet.
After here, we need to update.
Uh, we need to update the reaction cow right here also.
Right.
We need to.
Uh, get reaction now.
But that for the next video.
Uh, let me taste that.
Okay.
Let me taste that a bit.
Okay.
Right here.
I will get on, uh, boss.
Right here.
We have the ID.
Is that the ad reaction?
We need to create the controller.
Most over here are Russian.
General.
Something like that.
Okay.
Now let me take that.
I will boost the ID over here with the tie.
Will be like.
Let me say we have already got the success.
And let's check the data by.
Right here.
We already got a tie with the users.
Ready?
Uh, but.
I don't see the boss.
Oh, my bad, my bad.
The reason?
Because inside here.
This is the boss.
And this is the boss ID, right?
I want Every name is.
Big win right here.
Uh, we need to.
Add a bit.
If you say inside the create method, we take a look at video.
Right.
We need to.
Right.
Mouse over here.
We will create last body and.
Hi.
Okay.
We need to change a little bit over here and let me undo.
Okay.
This will work right now.
Before that let me remove the document.
Let me say it again.
And let's refresh.
Okay, well, now we already lost the boss lady right here and right here.
Okay.
And it all works.
But right now, if you save the boss over here.
We.
We need to update the count for us, right?
So not for the next video.
And I hope you understand the losses over here.
Okay, so if not, let's take a little bit.
I'm sure you will like that.
I will see you in the next one.