1
00:00:00,180 --> 00:00:00,560
Beautiful.

2
00:00:00,600 --> 00:00:06,450
So our initial functionality works pretty cool, where now I can aggregate how many applications we

3
00:00:06,450 --> 00:00:08,310
sent out in the last half of the year.

4
00:00:09,160 --> 00:00:16,660
But there's one thing that we need to do before we move on to the front and notice how we have charts.

5
00:00:17,290 --> 00:00:20,350
So we have one value account.

6
00:00:20,650 --> 00:00:24,790
So how many jobs and the second one is this form out of date?

7
00:00:25,710 --> 00:00:29,470
And even though it's really cool that we can get our data.

8
00:00:30,360 --> 00:00:36,000
I mean, at the moment, we have this underscore I.D. with year and month, and then they count.

9
00:00:36,750 --> 00:00:43,830
So I think it would be better if we would massage or factor this data on a back and before we send it

10
00:00:43,830 --> 00:00:44,150
back.

11
00:00:44,610 --> 00:00:47,600
Eventually, it's going to be way easier on the front end.

12
00:00:47,610 --> 00:00:55,290
If, let's say, instead of having this nice thin structure or simply have two things in that object.

13
00:00:55,830 --> 00:00:59,520
First of all, have the date and the second count.

14
00:01:00,000 --> 00:01:07,440
So how many items and or nicely format that year and month in a falling way?

15
00:01:07,860 --> 00:01:14,570
And the way we'll do that is going to be something like this where first we'll have to install moment

16
00:01:14,580 --> 00:01:16,290
jazz on the server.

17
00:01:16,410 --> 00:01:17,830
We already have it on the front end.

18
00:01:18,270 --> 00:01:21,300
But in this case, we will install it on the server.

19
00:01:22,140 --> 00:01:27,660
And again, we go with npm install moment, and I'll do that right away because it takes a little bit

20
00:01:27,660 --> 00:01:30,300
of time to spin everything up.

21
00:01:30,720 --> 00:01:39,150
So I just go here with npm install moment, and once we install the library, what's it going to spin

22
00:01:39,150 --> 00:01:40,290
up our server?

23
00:01:41,070 --> 00:01:41,550
Think of this.

24
00:01:41,550 --> 00:01:48,690
We're not going to close the terminal and then we want to import the moment in the jobs controller and

25
00:01:48,690 --> 00:01:53,070
then remember that we were setting up again monthly applications with let.

26
00:01:53,250 --> 00:01:54,180
And what does that mean?

27
00:01:54,570 --> 00:02:03,720
Well, that means that again, we can iterate over our monthly applications and return data in a different

28
00:02:03,720 --> 00:02:04,020
way.

29
00:02:04,530 --> 00:02:11,580
Where instead of this giant object, I'm going to pull out a year and a month on the security as well

30
00:02:11,580 --> 00:02:12,210
as the count.

31
00:02:12,450 --> 00:02:18,150
So all of those things are sitting there in object and you can double check that in the postman.

32
00:02:18,540 --> 00:02:23,370
And one will use moment to format our date.

33
00:02:24,260 --> 00:02:30,200
And we'll just send back the day and count in the object, so we'll return this new object.

34
00:02:30,500 --> 00:02:35,540
And then lastly, we'll have the reverse and I'll talk about the reverse once we get there.

35
00:02:36,020 --> 00:02:37,670
So let's go to the jobs controller.

36
00:02:37,910 --> 00:02:39,920
Want to start by grabbing the moment?

37
00:02:40,790 --> 00:02:47,200
So let's go here with important moment and then that is coming from the moment library.

38
00:02:47,460 --> 00:02:48,470
OK, beautiful.

39
00:02:49,340 --> 00:02:58,010
Now let's go to our stats or show stats controller and we have the monthly applications we have to set

40
00:02:58,010 --> 00:02:58,960
them up with.

41
00:02:58,990 --> 00:02:59,290
Let.

42
00:02:59,630 --> 00:03:01,190
So now let's iterate over it.

43
00:03:01,760 --> 00:03:06,020
We'll go with monthly applications is equal to monthly applications.

44
00:03:06,830 --> 00:03:10,640
And let's go with a map method we're iterating over.

45
00:03:10,790 --> 00:03:16,010
Remember each and every item that is an object and side of that object.

46
00:03:16,310 --> 00:03:20,480
These are our properties we have on our score ID, which is an object.

47
00:03:20,630 --> 00:03:24,080
And there we have a year and a month.

48
00:03:24,590 --> 00:03:26,840
And also we have the count.

49
00:03:27,290 --> 00:03:34,100
So all of our pulling out of the item and then let's create that new date using the moment.

50
00:03:34,670 --> 00:03:36,560
So we're going to go here with constant date.

51
00:03:37,040 --> 00:03:40,040
Then let's grab our moment.

52
00:03:40,460 --> 00:03:43,040
So that's the import we get from the library.

53
00:03:43,280 --> 00:03:48,080
And like I said, we can change it and essentially we can go with month method.

54
00:03:48,410 --> 00:03:50,480
We can pass here the month.

55
00:03:50,530 --> 00:03:58,220
And the reason why I'm subtracting one or here is simply because when it comes to moment, it counts

56
00:03:58,220 --> 00:04:05,150
those months zero to 11, where in MongoDB we're getting back one to 12.

57
00:04:05,510 --> 00:04:11,750
That's why in this month, method we process in month subtracted by one.

58
00:04:12,290 --> 00:04:17,750
And then we also want to do the same thing with a year, and let's pass in the year value and now its

59
00:04:17,750 --> 00:04:18,320
format.

60
00:04:18,829 --> 00:04:22,050
And essentially, we just need to come up with whatever format we want to return.

61
00:04:22,370 --> 00:04:29,930
My guess is that is going to be month, month, month and year like, so let's save this one, and let's

62
00:04:29,930 --> 00:04:33,230
not forget what we're going to be returning from the iteration.

63
00:04:33,470 --> 00:04:38,240
So let's just say over here that instead of that complex structure, we're going to go with the return

64
00:04:38,690 --> 00:04:41,090
date and count.

65
00:04:41,630 --> 00:04:44,750
And now before we set up the reverse, let's just check it out.

66
00:04:44,750 --> 00:04:44,860
What?

67
00:04:44,860 --> 00:04:45,920
We have an apportionment.

68
00:04:46,430 --> 00:04:47,960
So let me send it.

69
00:04:48,350 --> 00:04:49,640
OK, that looks about right.

70
00:04:50,090 --> 00:04:55,910
So I have over here bait as well as the count, and no additional date is nicely formatted.

71
00:04:56,660 --> 00:04:58,280
So we don't need this for our logic.

72
00:04:58,310 --> 00:05:01,610
Essentially, we just need it as far as our charts.

73
00:05:02,150 --> 00:05:07,700
And the reason why I want to reverse it because when it comes to the chart will actually have to pass

74
00:05:07,700 --> 00:05:10,120
in the oldest month.

75
00:05:10,160 --> 00:05:13,310
Now, in our case, that is, of course, that half a year.

76
00:05:13,610 --> 00:05:20,210
So let's say if this is December, the oldest month since we have only six of them is going to be July.

77
00:05:20,600 --> 00:05:23,090
The next one is August, September and all that.

78
00:05:23,660 --> 00:05:27,500
And that's why we all go here and a chain reverse.

79
00:05:27,950 --> 00:05:34,040
So instead of displaying the first month, the latest month, we'll start with an all this one.

80
00:05:34,610 --> 00:05:39,590
And before you look at the screen and start screaming that, Hey, listen.

81
00:05:39,920 --> 00:05:41,750
But why did we do this?

82
00:05:42,410 --> 00:05:43,850
Why don't we set up the sword?

83
00:05:44,300 --> 00:05:49,190
Well, we're we need to understand here is that we are limiting six.

84
00:05:49,250 --> 00:05:49,730
Correct.

85
00:05:50,180 --> 00:05:58,700
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

86
00:05:58,700 --> 00:06:03,290
this, then basically I'm going to get the oldest month.

87
00:06:03,710 --> 00:06:08,570
So those are going to be, I don't know, two or three years ago, and that's not what I want.

88
00:06:08,960 --> 00:06:13,220
So I definitely want to get the latest six months.

89
00:06:13,760 --> 00:06:22,370
So therefore I need to sort of I'm getting the latest values I'm limiting to six events since the chart

90
00:06:23,010 --> 00:06:28,310
is going to be displaying that they're starting from the oldest to the newest.

91
00:06:28,670 --> 00:06:30,140
That's why we reversed.

92
00:06:30,470 --> 00:06:34,790
Hopefully that is clear to me that one more time in a postman.

93
00:06:35,060 --> 00:06:36,230
And then it would be good to go.

94
00:06:36,680 --> 00:06:37,730
So let me save it.

95
00:06:37,730 --> 00:06:45,500
And I notice here I have July and my last item is going to be December, which is going to be displayed

96
00:06:45,890 --> 00:06:48,890
all the way on the right hand side in the chart.

