All right.
And up next, let's start working on the stats page.
And essentially in this page, we'll display how many applications are pending, how many interviews
we have, and also how many jobs are declined.
And also below will display two charts, one area chart and one bar chart, where effectively we'll
show how many applications we have sent out, basically how many jobs we have applied to in last six
months.
Now we're going to start in the server.
So essentially navigate to a job controller and create a new controller.
And then of course, we'll also set up the route and test it out.
Now, I do want to import two more things since we will implement them to set up the functionality and
that is Mongoose.
So lets just import mongoose from Mongoose.
And also we want to set up the JS.
So if you remember we used the JS package already in the client, so we're doing this on the server
as well.
Now if you need to install, just complete the steps.
But if you.
Installed all the packages together with me, then you should have already de JS in the package Json.
And if that's the case of course then you just need to import.
So we're looking for De and this is coming from De JS.
Let's save it.
Let's scroll down.
We're looking for the controller and in my case I'm going to call this show stats.
So export const, show stats.
It's going to be a sync of course, so let's set it up req and res and then in the function body.
For now, let's just go with Res.send and let's call this stats then in the job router, we want to
grab the show stats.
And then in between the forward slash and then forward slash ID set up the stats.
And this is very, very important.
We want to place stats before the ID because otherwise if you place it after Express is just going to
think that stats is the ID that we're passing in.
Since express reads top to bottom, so we're going to go here with router dot route, then forward slash
stats and then we want to set up which.
Method we're looking for.
And in my case that is get.
And of course now I want to go with show stats.
Then we want to navigate to a Thunder client collections, recording job routes.
And let's add one more.
Now since this is a get route, I'll simply just duplicate this one over here.
Then let's right away rename, I'll say show stats and then in here the URL jobs.
We just need to add forward slash stats.
It's a get route.
I send it and check it out.
Now I have 401.
So it looks like I also need to log in.
Let me navigate to a login user.
Let me send it over here.
Okay, good.
And then let me try it one more time.
Show stats and we're good to go.
And the last thing that I want to do in this video is to hardcode the example data we're going to send
back.
So yes, in the following videos, of course, we'll set up the functionality where we'll use MongoDB
aggregation pipeline to count all of those values.
But for now I just want to showcase what the front end is looking for and hopefully this is going to
help us when we're setting up the functionality.
So you'll have a clear guideline what we need to send back.
So long story short, I want to come back to the show stats and let me, like I said, just hard code
here, default stats.
That's my object over here.
And effectively we want to send back three properties.
So since the job status has potential values of pending interview and decline, this is what we're going
to count.
So essentially there's going to be functionality where we'll look at our database more specifically
to the jobs that belong to that specific user, and it will count well, how many are pending, how
many have interview and decline?
And again, at the moment I'm just hard coding that.
But eventually this will be dynamic and I'm just going to provide some values over here.
So this will be equal to interview, I'll say 11 and then the client is equal to four.
Again, this part is going to be dynamic.
The main point that I'm trying to make is.
When it comes to the server, this is what we're sending back eventually.
This is what is going to be in our outgoing response.
And you know what?
Let me just.
Provide proper status over here.
We want to go with status codes and then.
Okay, then of course we'll go with Json here, dot Json.
And then as far as the object, I'm just going to pass default stats and also we'll set up monthly applications.
So when it comes to default stats, there are going to be displayed over here in the stack containers.
And then when it comes to the monthly applications, we'll display them over here with the charts library.
And when it comes to monthly applications, like I said, we want to send back last six months.
And essentially how many applications we have sent out.
And therefore, in here I'm going to go with let and monthly.
Applications.
It's going to be equal to an array.
And again, I'm hardcoding right now.
Eventually this will be dynamic and basically the syntax, the front end is looking for.
More specifically, the charts library is following.
We're going to provide date and in this case, I'm just going to go with May 23rd, meaning May of year
2023.
And then how many applications will count is going to be equal to 12.
And I'm not going to write six months, but I will set up three.
So essentially we'll send back.
Account for every month for the last six months.
So in this case, I'm going to go with June.
And then lastly, we also want to set up the July.
Now, keep in mind that.
The order needs to be exact because that's my preference as far as setting up the front end.
So what I mean by that.
Notice how the latest month is actually the last one in the array.
And if we take a look at the front end notice, of course, in this case, this is May since I haven't
created more applications.
But the idea doesn't change where the latest month is going to be.
Last one.
And then we go one before, one before.
And again, we're looking for six months.
And in here I want to add a comma and I'll provide monthly applications.
So this is what we're sending back.
So now let's go back to show stats.
Let's send it.
And again, as far as the front end.
So basically by the time we're done with the functionality on a server, this is what we're going to
be sending back.
And the only difference is that of course it's not going to be hardcoded.
So as far as the structure, yes, it's going to be exactly the same.
Difference, of course, is that it's going to be dynamic.
So we'll calculate based on the jobs that the user has and we'll send back such response.
And with this in place, we can proceed to the next step.