All right.
We're almost almost almost one setting up the functionality on the server when it comes to pagination.
The only thing that is missing right now is the correct value for total jobs.
And we're also not displaying how many pages we have in total because this is very important for us
on the frontend on first, Oatman showcase the total jobs issue.
We're at the moment we're relying on jobs, not length.
But keep in mind that in order to get the jobs, we already used the limit and where I'm going with
this is the fact that total jobs will always reflect the limit in our current set up.
So if I'm going to go here with 10, if I'll send it, I'm going to get back total jobs then and then
if I'll change this around to 25, you can already guess that this value will be 25.
And what is the problem?
Well, on a front end, I actually want to showcase how many total jobs I got with this query, because
at the moment I'm just displaying how many jobs per page I'm displaying.
And that's not what I want.
And the second thing is, like I said, number of pages.
So how many pages we have total because that's going to be very nifty for us when we set up our button
container.
And in order to fix that.
Here's what we're going to do after we await the result, set up another await, and in this case,
we're going to go with the job, then count documents.
That's the method.
And essentially, this method counts the documents, but I don't want to count all the job documents.
And what's really cool actually can pass in the same query object.
So in this case, I'm just getting back.
Well, how many total jobs I have for that specific query.
So that's going to get me the total jobs.
And in this case, it's not going to be relying on the limit, it's going to be independent.
And when it comes to number of pages, I'm going to go with the math that ceiling because we'll always
rounded up and will divide total jobs by the limit we have.
So let's say I have 75 jobs.
I'll divide this by 10, which is my limit, my default one.
And that will give me 7.5 pages.
Now, I don't want to displace 7.5.
I actually went around it up because I'll have seven pages would find jobs among the eighth one is going
to have the remaining jobs.
In my case, five of us makes sense.
So let's go to a jobs controller and let's set up both of those things.
So first, we want to go with Konst Total and then jobs and not as equal to 08.
But again, we go with our model.
The job model than that.
And then, like I said, the method name is count documents and we just want to pass in the query object.
One, let's count the number of pages and we're going to do that by again, math that ceiling and then
we'll divide total jobs by the element.
So let's go here with number of pages than let's use the math that ceiling.
And let's pass in total jobs divided by the limit.
Now I just need to fix our third one.
The old jobs is not going to equal to a jobs, not length.
Again, jobs length is actually being controlled right now with a limit.
So it's remove it.
And instead of hard coding that one, we're going to go with.
Number of pages, essentially, we'll set it equal to this variable.
And once we say right now, you'll notice that regardless of what is the limit over here, actually
get total jobs correctly.
So this is going to be certified and check it out.
What we're controlling with the limit right now is the number of pages, but total jobs won't change.
So if I'll change this one to 25, you'll notice.
But I'll have three total pages because again, our total job is going to be 75 divided by the 25,
which is going to be three.
But this one will always stay 75 knots, the look that I want on the front end.
And with this in place now, I can start setting up the frontend functionality.