1
00:00:00,000 --> 00:00:00,360
Okay.

2
00:00:00,360 --> 00:00:04,140
Hopefully we're clear on the query string parameter basics.

3
00:00:04,290 --> 00:00:07,320
And up next, let's kick it up a notch.

4
00:00:07,350 --> 00:00:11,200
You see, our current setup has three major issues.

5
00:00:11,220 --> 00:00:17,520
First of all, search parameter or any other parameter for that matter can be empty.

6
00:00:17,730 --> 00:00:19,350
And if that's the case.

7
00:00:20,100 --> 00:00:22,440
Essentially we'll get back empty array.

8
00:00:22,500 --> 00:00:26,970
So it would be nice if we could add a search parameter based on the condition.

9
00:00:26,970 --> 00:00:29,690
So essentially, if there's some kind of value, Yes.

10
00:00:29,700 --> 00:00:32,810
Use it in order to search for a jobs.

11
00:00:32,850 --> 00:00:39,600
If it's empty, if there's no value or it's not provided at all, well then don't use it then.

12
00:00:39,600 --> 00:00:41,930
Basically get me back all of the jobs.

13
00:00:41,940 --> 00:00:47,610
Now, second issue, we're searching for jobs based on the exact match.

14
00:00:47,610 --> 00:00:54,270
So let's say I'm going to make some kind of typo over here and make the request notice I'll get back

15
00:00:54,270 --> 00:01:01,080
empty array because there are no jobs where position matches exactly to this value.

16
00:01:01,380 --> 00:01:04,110
And in order to fix it, we'll use regex.

17
00:01:04,170 --> 00:01:09,870
So essentially, instead of looking for the exact match, I'm going to say, Hey, listen, if this

18
00:01:09,870 --> 00:01:13,950
value is somewhere there, then return the job.

19
00:01:14,100 --> 00:01:18,930
And lastly, I want to search both the company and the position.

20
00:01:19,020 --> 00:01:26,680
So when I'm searching, not only I want to get the results from the company, but also from the position.

21
00:01:26,680 --> 00:01:29,560
And I guess let's start with the empty value first.

22
00:01:29,560 --> 00:01:33,130
So let me just showcase it just so you don't think that I'm messing with you.

23
00:01:33,900 --> 00:01:38,310
If I remove everything from the search parameter value, check it out.

24
00:01:38,310 --> 00:01:44,670
I get back empty jobs array and in order to fix it, we'll use following approach.

25
00:01:44,790 --> 00:01:46,760
Notice how this is an object.

26
00:01:46,770 --> 00:01:47,300
Correct?

27
00:01:47,310 --> 00:01:48,620
The filter object.

28
00:01:48,630 --> 00:01:50,250
So here's what I want to do.

29
00:01:50,280 --> 00:01:55,290
I want to set it up separately above job dot find.

30
00:01:55,440 --> 00:02:00,330
I'll add the search parameter and some other ones as well.

31
00:02:00,330 --> 00:02:07,530
We'll set them up as properties and if it's present, then we'll add to the object and then we'll use

32
00:02:07,530 --> 00:02:08,610
it in our search.

33
00:02:08,610 --> 00:02:11,880
If not, then of course we will skip it.

34
00:02:11,910 --> 00:02:15,270
So long story short, here's what we want to do.

35
00:02:15,830 --> 00:02:24,470
For starters, let's start destructuring the parameters which are coming from rec dot query.

36
00:02:24,520 --> 00:02:27,730
Now for now we only have search, but there are going to be more.

37
00:02:27,740 --> 00:02:30,440
So I'll set it equal to rec dot query.

38
00:02:30,440 --> 00:02:36,470
And then like I said, I want to construct the object and in my case I'm going to call this query object.

39
00:02:36,920 --> 00:02:39,620
Now which property always is going to be there?

40
00:02:39,650 --> 00:02:41,190
Well that's the created by.

41
00:02:41,210 --> 00:02:41,800
Correct.

42
00:02:41,810 --> 00:02:49,130
So I can just take this one out over here and then instead of hard coding everything, I'll say, you

43
00:02:49,130 --> 00:02:49,560
know what?

44
00:02:49,580 --> 00:02:51,840
There's going to be a query object.

45
00:02:51,860 --> 00:03:01,100
So now I can set up a condition where I'll say, Hey, listen, if search exists, then add it to a

46
00:03:01,130 --> 00:03:01,850
query object.

47
00:03:01,850 --> 00:03:07,040
If it's not basically there is no value, then just skip it.

48
00:03:07,070 --> 00:03:13,130
Now for now, I'll just use the exact match and then in a second we'll set up the rejects.

49
00:03:13,130 --> 00:03:15,470
So I'll say if search exists.

50
00:03:15,470 --> 00:03:21,260
So essentially, if there's some kind of value, then I want to go with query object.

51
00:03:21,380 --> 00:03:26,960
Remember, we need to provide the properties which are on our model.

52
00:03:27,320 --> 00:03:28,610
So this doesn't change.

53
00:03:28,610 --> 00:03:30,050
Notice how this is created by.

54
00:03:30,050 --> 00:03:36,600
So of course, if I want to look for specific property, it needs to match whatever I have in the model.

55
00:03:36,600 --> 00:03:41,520
So in this case, we want to go with position and we want to set it equal to.

56
00:03:42,820 --> 00:03:46,570
Rec dot query and search.

57
00:03:46,570 --> 00:03:49,370
So we only add it if it exists.

58
00:03:49,390 --> 00:03:52,570
If it doesn't, then of course we don't do anything.

59
00:03:52,570 --> 00:03:54,470
So now let's navigate back.

60
00:03:54,490 --> 00:03:55,520
Let's send it here.

61
00:03:55,540 --> 00:04:00,380
Now get all the jobs because we don't add it to our filter object.

62
00:04:00,400 --> 00:04:01,870
However, if.

63
00:04:02,330 --> 00:04:04,460
Of course I'm going to provide some kind of value.

64
00:04:05,540 --> 00:04:06,590
And send it notice.

65
00:04:06,590 --> 00:04:07,880
I'll get that one job.

66
00:04:08,270 --> 00:04:10,550
Okay, so we fixed the first issue.

67
00:04:10,580 --> 00:04:13,820
Up next, let's work on that exact match.

68
00:04:13,850 --> 00:04:19,339
You see, if I'll provide some kind of value, for example, a and if I'll send it, I'll get back.

69
00:04:19,339 --> 00:04:24,950
No jobs because there are no jobs where the position is equal to a.

70
00:04:25,070 --> 00:04:31,880
So again, a better approach is to use regex and say, hey, listen, get me the jobs where in the company

71
00:04:31,880 --> 00:04:34,370
and position property.

72
00:04:34,950 --> 00:04:42,180
The values have a So let's navigate back over here job controller and instead of setting query object

73
00:04:42,180 --> 00:04:49,500
position to req dot query dot search, I want to remove both of them and then the syntax is following.

74
00:04:49,500 --> 00:04:51,510
We're going to go here with dollar sign.

75
00:04:51,510 --> 00:04:54,570
Or again, this is a mongo syntax.

76
00:04:54,570 --> 00:04:59,570
We'll set it equal to an array and there's going to be two objects.

77
00:04:59,580 --> 00:05:07,530
First of all, we'll say position again property, which we have in our model, and then we'll go with

78
00:05:07,530 --> 00:05:12,270
dollar sign again rejects and we'll set it equal to our search.

79
00:05:12,450 --> 00:05:14,940
So that's req dot, query, dot search.

80
00:05:14,940 --> 00:05:20,340
And as a side note, of course in the previous example I could have just used search instead of req

81
00:05:20,340 --> 00:05:21,870
dot query dot search.

82
00:05:21,900 --> 00:05:23,340
Please keep that in mind.

83
00:05:23,340 --> 00:05:29,520
And also I want to provide the options and I'll say I don't care about the casing, so I'll go here

84
00:05:29,520 --> 00:05:31,470
with I let's save it.

85
00:05:31,470 --> 00:05:35,650
And we want to do the same thing for the company as well.

86
00:05:35,650 --> 00:05:38,560
So let me add a comma over here.

87
00:05:40,310 --> 00:05:43,700
Copy and paste and instead of position.

88
00:05:44,380 --> 00:05:51,160
We're going to go here with company and now we're going to navigate back and check it out.

89
00:05:51,280 --> 00:06:00,070
Essentially, now I'm getting all of the jobs where there is a in the position or the company.

90
00:06:00,850 --> 00:06:05,770
And of course, if I'm going to remove and if I'm not going to provide anything in a search, then I'm

91
00:06:05,770 --> 00:06:07,720
going to get back all of the jobs.

92
00:06:07,720 --> 00:06:14,140
Since now we're not adding the search param to our filter object.

93
00:06:14,140 --> 00:06:17,650
And with this in place now we can move on to the next step.

