1
00:00:00,470 --> 00:00:02,930
And up next, let's talk about the sorting.

2
00:00:02,960 --> 00:00:08,960
Now, first of all, I want you to understand that when it comes to sorting, we're not changing the

3
00:00:08,960 --> 00:00:12,000
amount of jobs we're going to send back.

4
00:00:12,020 --> 00:00:14,000
We're changing the order.

5
00:00:14,180 --> 00:00:15,980
And this is very, very important.

6
00:00:16,340 --> 00:00:19,820
And basically, the main functionality looks like this.

7
00:00:19,880 --> 00:00:24,420
In the manga we have this sort method which we can chain.

8
00:00:24,440 --> 00:00:30,170
So we have over here this job dot find and we can also add sort.

9
00:00:30,290 --> 00:00:31,660
And the syntax is following.

10
00:00:31,670 --> 00:00:33,420
We pass here the string.

11
00:00:33,440 --> 00:00:38,270
And then for example, if I want to get the latest jobs first.

12
00:00:38,270 --> 00:00:45,890
So basically where the date is, the most recent date I want to go here with minus and then created

13
00:00:45,920 --> 00:00:46,940
at Y.

14
00:00:46,970 --> 00:00:47,730
Created at.

15
00:00:47,750 --> 00:00:50,090
Well, because that's where we have the date.

16
00:00:50,090 --> 00:00:54,920
And again, this is going to return everything in the descending order.

17
00:00:54,950 --> 00:00:56,480
So let me save it here.

18
00:00:57,050 --> 00:01:01,010
Again, I'm not going to change anything about the parameters here.

19
00:01:01,040 --> 00:01:02,130
Let me just send it.

20
00:01:02,150 --> 00:01:11,050
And if we take a look at it, we'll see that this is going to be 20, 23, then zero six then created.

21
00:01:11,050 --> 00:01:12,170
That should be less.

22
00:01:12,170 --> 00:01:14,180
So notice over here it's zero five.

23
00:01:14,180 --> 00:01:17,420
And as you can see, we have this descending order.

24
00:01:17,450 --> 00:01:24,140
Now, if we want the oldest ones, basically, if we want the ascending order, then we just want to

25
00:01:24,140 --> 00:01:25,070
remove this minus.

26
00:01:25,070 --> 00:01:30,380
And again, let's send it and notice the amount of jobs is still the same.

27
00:01:30,380 --> 00:01:33,560
But of course, this is the opposite of the latest date.

28
00:01:33,590 --> 00:01:39,110
So this pretty much is the oldest date that I have in the database.

29
00:01:39,260 --> 00:01:42,350
And also, we can do the same thing for the letters.

30
00:01:42,350 --> 00:01:46,370
For example, if I want to start with A to Z, I just need to pick the property.

31
00:01:46,370 --> 00:01:48,340
In my case, it's going to be position.

32
00:01:48,350 --> 00:01:54,920
And if I want to start with Z to A, then I want to go with the minus and then position.

33
00:01:54,950 --> 00:01:56,540
So let's try it out.

34
00:01:56,750 --> 00:02:00,290
Basically in here I'm going to type position.

35
00:02:01,150 --> 00:02:04,960
Let's again send this should be A to Z.

36
00:02:04,990 --> 00:02:05,740
Check it out.

37
00:02:05,770 --> 00:02:09,080
Now I start with a and of course, if I keep on scrolling.

38
00:02:09,100 --> 00:02:15,580
Now, this is going to be equal to E, And if I try over here with this minus, then of course it's

39
00:02:15,580 --> 00:02:16,730
going to be opposite.

40
00:02:16,750 --> 00:02:22,180
So we start over here with S, but again, we want to make this dynamic.

41
00:02:22,180 --> 00:02:23,950
So how is that going to look like?

42
00:02:23,980 --> 00:02:30,940
Well, for starters, we're not going to hardcode it and we're going to go right after both of these

43
00:02:30,940 --> 00:02:31,840
conditions.

44
00:02:31,870 --> 00:02:33,670
I'll construct a new object.

45
00:02:33,700 --> 00:02:37,820
I'll say const and I'm going to call this sort options.

46
00:02:37,840 --> 00:02:39,040
That's my object.

47
00:02:39,040 --> 00:02:43,320
And as far as the properties, well, I'm just going to provide the values that I'm looking for.

48
00:02:43,330 --> 00:02:45,280
So the first one is going to be newest.

49
00:02:45,280 --> 00:02:46,900
And remember the syntax.

50
00:02:46,900 --> 00:02:48,400
We want to go here with the minus.

51
00:02:48,400 --> 00:02:50,560
Basically, we want to go with descending.

52
00:02:50,560 --> 00:02:52,960
And the property name is Createdat.

53
00:02:52,990 --> 00:02:59,020
Yes, of course, this property name needs to match, otherwise it's not going to make sense.

54
00:02:59,170 --> 00:03:01,820
Then I want to set up the oldest.

55
00:03:03,080 --> 00:03:05,600
And this is going to be just createdat.

56
00:03:05,630 --> 00:03:08,720
Then let's add a comma since that's the syntax.

57
00:03:08,720 --> 00:03:10,850
And then let's set up two properties.

58
00:03:10,880 --> 00:03:17,810
One is going to be for A to Z, and in this case, we're looking for position and looks like I'm just

59
00:03:17,810 --> 00:03:19,910
skipping on the commas for some reason.

60
00:03:19,910 --> 00:03:27,500
And then if I want to go to Z to A, then we want to set it equal to minus and then position, let's

61
00:03:27,500 --> 00:03:28,160
save it.

62
00:03:28,160 --> 00:03:32,430
And in here, basically we want to set up a sort key.

63
00:03:32,450 --> 00:03:38,420
So I'm going to go with const sort key and this is going to be equal to sort options.

64
00:03:38,420 --> 00:03:43,310
And now of course I want to look for the specific parameter.

65
00:03:43,310 --> 00:03:49,760
So essentially I want to grab the sort out of the req dot query and then back where I have the sort

66
00:03:49,790 --> 00:03:54,730
key, I'll use it to get the property value.

67
00:03:54,740 --> 00:03:58,100
So essentially I'm looking for the property dynamically here.

68
00:03:58,130 --> 00:04:00,230
That's why I have the square brackets.

69
00:04:00,230 --> 00:04:06,540
And if for some reason the value is not there, I'll simply go with some default one.

70
00:04:06,540 --> 00:04:11,160
So I'll say sort options and then dot newest.

71
00:04:11,160 --> 00:04:19,920
So if everything fails then basically sort based on the createdat but go in the descending order.

72
00:04:19,920 --> 00:04:30,120
So if I navigate to dot find and if I just add here sort in this case, I want to add that sort key.

73
00:04:30,150 --> 00:04:36,300
So now let's navigate back to get all jobs and let's add that parameter over here.

74
00:04:36,300 --> 00:04:43,350
And again, if we don't provide anything, everything is fine because we still use that newest notice.

75
00:04:43,350 --> 00:04:46,910
We have 20, 23 and then zero six.

76
00:04:46,920 --> 00:04:51,750
Now, if I'm going to provide over here, the oldest now check it out.

77
00:04:51,750 --> 00:04:58,260
I make the request and now I'm actually getting the oldest jobs in my database.

78
00:04:58,500 --> 00:05:04,770
And similarly, if I want a to Z, I'm just going to type here A to Z, That's the value.

79
00:05:04,770 --> 00:05:11,160
So now we start with A and then if we want Z to A, you can probably already guess we're going to start

80
00:05:11,160 --> 00:05:13,050
with that's over here.

81
00:05:13,080 --> 00:05:20,520
Now, of course, on the front end, all of these values are going to be already set in the select input

82
00:05:20,550 --> 00:05:24,240
because if you recall, we already set them up in the utils.

83
00:05:24,240 --> 00:05:30,510
So if I navigate back over here to utils folder, then constants, check it out.

84
00:05:30,540 --> 00:05:35,430
We already have these values, so this is how we're going to set it on the front end.

85
00:05:35,430 --> 00:05:40,410
And with this in place now we can start dealing with the pagination.

