Beautiful.
So our initial functionality works pretty cool, where now I can aggregate how many applications we
sent out in the last half of the year.
But there's one thing that we need to do before we move on to the front and notice how we have charts.
So we have one value account.
So how many jobs and the second one is this form out of date?
And even though it's really cool that we can get our data.
I mean, at the moment, we have this underscore I.D. with year and month, and then they count.
So I think it would be better if we would massage or factor this data on a back and before we send it
back.
Eventually, it's going to be way easier on the front end.
If, let's say, instead of having this nice thin structure or simply have two things in that object.
First of all, have the date and the second count.
So how many items and or nicely format that year and month in a falling way?
And the way we'll do that is going to be something like this where first we'll have to install moment
jazz on the server.
We already have it on the front end.
But in this case, we will install it on the server.
And again, we go with npm install moment, and I'll do that right away because it takes a little bit
of time to spin everything up.
So I just go here with npm install moment, and once we install the library, what's it going to spin
up our server?
Think of this.
We're not going to close the terminal and then we want to import the moment in the jobs controller and
then remember that we were setting up again monthly applications with let.
And what does that mean?
Well, that means that again, we can iterate over our monthly applications and return data in a different
way.
Where instead of this giant object, I'm going to pull out a year and a month on the security as well
as the count.
So all of those things are sitting there in object and you can double check that in the postman.
And one will use moment to format our date.
And we'll just send back the day and count in the object, so we'll return this new object.
And then lastly, we'll have the reverse and I'll talk about the reverse once we get there.
So let's go to the jobs controller.
Want to start by grabbing the moment?
So let's go here with important moment and then that is coming from the moment library.
OK, beautiful.
Now let's go to our stats or show stats controller and we have the monthly applications we have to set
them up with.
Let.
So now let's iterate over it.
We'll go with monthly applications is equal to monthly applications.
And let's go with a map method we're iterating over.
Remember each and every item that is an object and side of that object.
These are our properties we have on our score ID, which is an object.
And there we have a year and a month.
And also we have the count.
So all of our pulling out of the item and then let's create that new date using the moment.
So we're going to go here with constant date.
Then let's grab our moment.
So that's the import we get from the library.
And like I said, we can change it and essentially we can go with month method.
We can pass here the month.
And the reason why I'm subtracting one or here is simply because when it comes to moment, it counts
those months zero to 11, where in MongoDB we're getting back one to 12.
That's why in this month, method we process in month subtracted by one.
And then we also want to do the same thing with a year, and let's pass in the year value and now its
format.
And essentially, we just need to come up with whatever format we want to return.
My guess is that is going to be month, month, month and year like, so let's save this one, and let's
not forget what we're going to be returning from the iteration.
So let's just say over here that instead of that complex structure, we're going to go with the return
date and count.
And now before we set up the reverse, let's just check it out.
What?
We have an apportionment.
So let me send it.
OK, that looks about right.
So I have over here bait as well as the count, and no additional date is nicely formatted.
So we don't need this for our logic.
Essentially, we just need it as far as our charts.
And the reason why I want to reverse it because when it comes to the chart will actually have to pass
in the oldest month.
Now, in our case, that is, of course, that half a year.
So let's say if this is December, the oldest month since we have only six of them is going to be July.
The next one is August, September and all that.
And that's why we all go here and a chain reverse.
So instead of displaying the first month, the latest month, we'll start with an all this one.
And before you look at the screen and start screaming that, Hey, listen.
But why did we do this?
Why don't we set up the sword?
Well, we're we need to understand here is that we are limiting six.
Correct.
So I do want to get my latest jobs first, and I want to limit to six because if I'm not going to do
this, then basically I'm going to get the oldest month.
So those are going to be, I don't know, two or three years ago, and that's not what I want.
So I definitely want to get the latest six months.
So therefore I need to sort of I'm getting the latest values I'm limiting to six events since the chart
is going to be displaying that they're starting from the oldest to the newest.
That's why we reversed.
Hopefully that is clear to me that one more time in a postman.
And then it would be good to go.
So let me save it.
And I notice here I have July and my last item is going to be December, which is going to be displayed
all the way on the right hand side in the chart.