WEBVTT 00:05.630 --> 00:05.960 All right. 00:05.980 --> 00:08.290 So hopefully you managed to find the solution. 00:08.380 --> 00:13.410 So before we start let's run 00:16.850 --> 00:22.910 a simple query using all the promises. 00:23.480 --> 00:24.950 So I'm gonna go for 00:30.110 --> 00:30.590 make 00:33.610 --> 00:34.800 you call something 00:37.990 --> 00:38.490 so you know. 00:38.500 --> 00:39.750 Use fake values for now. 00:39.770 --> 00:43.240 Is see our query and 00:46.630 --> 00:49.930 Mondale equals something and 00:54.800 --> 00:55.970 yeah equals 00:59.780 --> 01:03.320 and transmission 01:05.780 --> 01:14.990 and mean price and maximize. 01:15.430 --> 01:19.390 So this will show us what the query is going to look like. 01:19.390 --> 01:21.790 So let's go back to our code. 01:22.150 --> 01:31.150 So inside the filter method we gonna place our check function which will filter the different cars so 01:31.240 --> 01:34.570 the check function is going to return true or false. 01:34.600 --> 01:39.000 So if a if it's a much then it's gonna be true otherwise it's going to be false. 01:39.010 --> 01:41.320 So it's called s function check. 01:42.610 --> 01:46.800 So I'm going to define check. 01:47.750 --> 01:48.040 All right. 01:48.050 --> 01:48.190 But 01:57.090 --> 02:03.340 so this function will take a car object as a promise. 02:04.890 --> 02:09.600 And it's going to return true or false. 02:13.100 --> 02:25.780 So basically it's going to be true if you've got a match for each of these in the query so let's start 02:25.810 --> 02:27.630 with the make. 02:27.640 --> 02:36.570 So the make is going to be a match for Vasco if the user is looking for Audi. 02:36.570 --> 02:38.800 Well he's gonna be a match as well. 02:38.820 --> 02:44.250 If the user doesn't specify the make it's all businesses. 02:44.500 --> 02:45.140 Right. 02:45.590 --> 02:57.430 So what we need to do is return the results of a logical expression. 02:57.820 --> 03:03.650 So first let's check the make so you're going to have true if 03:06.640 --> 03:09.220 the query dot make 03:12.440 --> 03:30.110 is not defined is undefined right or the query dots make is the same as the car don't make agree. 03:30.620 --> 03:31.100 Perfect. 03:31.940 --> 03:37.060 Well sometimes the user might use capital letters in the values. 03:37.070 --> 03:40.990 So we will just we'll just turn this to lowercase 03:47.980 --> 03:48.580 like that's 03:55.640 --> 04:04.570 and the same thing will apply to all the other promises so we checking the make 04:09.850 --> 04:10.360 and 04:20.110 --> 04:20.800 the model 04:28.150 --> 04:28.690 the year 04:36.670 --> 04:37.640 v transmission 04:50.440 --> 04:55.280 is going to be different when it comes to the mean price and market price. 04:55.300 --> 04:58.750 So either the mean price is undefined 05:04.210 --> 05:17.200 or the query Min price is less than the car mid price. 05:19.050 --> 05:34.000 And we need to make sure that we pass this to an integer using the pass in function. 05:35.650 --> 05:37.710 We're gonna do the same thing with the max price 05:50.850 --> 05:51.380 okay. 05:54.540 --> 06:06.910 So this is our function check and now the output of this should be the correct cars to display. 06:06.910 --> 06:13.980 So for each of those results we're going to print the car with its details. 06:13.990 --> 06:20.730 So for each he's gonna take I promise I'm gonna call car reversing referring to the value of our item 06:22.360 --> 06:36.180 and we're going to run this function which will write into the body of the response using response dos 06:36.240 --> 06:43.410 right. 06:43.480 --> 06:48.610 Okay so let's start with a picture. 06:48.610 --> 06:50.610 So first let's have a line break. 06:52.850 --> 07:02.740 And then an image you can assess the source of the image to the URL property of the car 07:06.920 --> 07:11.150 which is car dot you until right. 07:11.760 --> 07:16.860 And that sets the height of our picture to something like 200 07:21.530 --> 07:25.180 analysts also sets all its attributes. 07:25.210 --> 07:27.220 Let's say that two car for example 07:34.000 --> 07:36.610 let's go for the Make 07:49.220 --> 07:50.720 let's go for the model 07:56.410 --> 07:56.780 here 08:01.590 --> 08:09.280 transmission. 08:09.470 --> 08:12.500 Maybe something on the price 08:23.360 --> 08:25.150 though before testing the code. 08:25.190 --> 08:31.510 I'm going to amend a few things so I need to close the image tag right there. 08:31.820 --> 08:35.230 And also this is supposed to be cars. 08:35.250 --> 08:42.380 Most car because we named our cars array cars and also disappearing mind. 08:42.380 --> 08:42.950 That's 08:45.550 --> 08:46.000 these 08:49.210 --> 08:51.190 variables like bath name. 08:51.430 --> 08:54.500 They are actually blocks scoped there. 08:55.360 --> 09:02.450 So we will need to run the full code inside this if statement. 09:02.940 --> 09:21.760 I'm going to copy all those like this. 09:21.860 --> 09:25.700 Place it right there and that form once the code 09:30.940 --> 09:31.270 all right. 09:31.290 --> 09:32.410 So perfect. 09:32.450 --> 09:36.120 So let's try. 09:36.150 --> 09:36.640 OK. 09:36.660 --> 09:37.590 All before doing that 09:40.340 --> 09:50.970 we actually turned the queries while use to lowercase but we haven't done that for the car parties. 09:51.410 --> 09:59.040 So we can either use lowercase for all of them otherwise we will need to turn them to lowercase as well. 09:59.350 --> 10:07.470 So what we need to do you can just add two lowercase to all these so you're only about for the year 10:07.760 --> 10:16.500 actually. 10:16.560 --> 10:23.460 And by the way this is supposed to be car dots Brice and car lots price. 10:23.520 --> 10:29.930 All right so let's save this and restarts are up. 10:30.240 --> 10:30.840 Try this 10:33.910 --> 10:37.670 so if we try with all cars we get all cars. 10:37.720 --> 10:41.730 So try a query so transmission automatic for example. 10:41.770 --> 10:51.990 So we get only automatic cars so only one car is automatic this try me price eleven thousand. 10:51.990 --> 10:57.530 So we get only cars with a price greater than eleven thousand. 10:57.760 --> 10:58.710 So let's try. 10:58.740 --> 11:03.470 Max Price ten thousand. 11:03.510 --> 11:10.400 We don't get any car even though we've got one car with a price of 10000. 11:10.470 --> 11:17.760 So change this one to less than or equal that one to greater than or equal. 11:17.760 --> 11:22.650 So let's save and restart our ab. 11:22.800 --> 11:26.300 Let's try again and this time it works. 11:26.370 --> 11:30.790 OK so let's try something else. 11:30.790 --> 11:35.800 Let's try the year. 11:35.860 --> 11:37.570 Let's go for 2018 11:40.690 --> 11:41.110 Great 11:43.810 --> 11:57.940 so let's try to promises so let's check cars with a year of two thousand 18 and is go for a min price 12:00.710 --> 12:01.880 or fifteen thousand 12:05.790 --> 12:09.430 and you get only that one OK. 12:09.430 --> 12:10.570 Perfect. 12:10.680 --> 12:13.430 Just a quick comment before moving to the next video. 12:13.750 --> 12:18.260 This is something that you would do normally using a database. 12:18.340 --> 12:26.440 So we've done that in this exercise just to get introduced to the U RL module and be able to manipulate 12:26.770 --> 12:32.120 you or else pass them manipulate queries and their parameters. 12:32.170 --> 12:39.070 So it's still a good exercise to start but we're going to cover databases in detail later on in the 12:39.070 --> 12:39.910 course. 12:39.940 --> 12:47.260 So in the next video you're going to get introduced to the file system module or the FSA module which 12:47.260 --> 12:50.740 is another great built in node module.