WEBVTT

1
00:00:02.060 --> 00:00:06.580
And with that, we got all these event controller functions linked to the routes.

2
00:00:06.940 --> 00:00:11.500
Now what we can also do is get rid of these prefixes here, slash events, because that

3
00:00:11.500 --> 00:00:15.740
prefix will actually be added one level above in the app.js file.

4
00:00:15.900 --> 00:00:20.800
In this routes file, I only have events routes, and this prefix doesn't need to be repeated

5
00:00:20.800 --> 00:00:21.180
here.

6
00:00:23.200 --> 00:00:31.300
So I'll actually select all of that and just delete it, and add a slash here, and also

7
00:00:31.300 --> 00:00:31.780
here.

8
00:00:34.380 --> 00:00:38.760
Okay, now we can go to app.js and make sure that the event routes are added here.

9
00:00:39.180 --> 00:00:47.320
And here, I'm probably quickest if I just do that manually and import my events routes

10
00:00:47.460 --> 00:00:50.680
from routes events.js, thanks for auto-completing this.

11
00:00:51.180 --> 00:00:58.540
And then here, I can app.use slash events and point at the events routes.

12
00:00:58.880 --> 00:01:01.800
And that's this slash events prefix I mentioned a second ago.

13
00:01:03.760 --> 00:01:09.080
Okay, so that was a lot of talking about this, but let's see whether this now works.

14
00:01:10.880 --> 00:01:15.280
For that, I'll now run npm run dev to start that development server, and I got an error.

15
00:01:17.420 --> 00:01:22.260
Cannot find module database.js imported in the event.js file.

16
00:01:24.340 --> 00:01:25.660
Let's see.

17
00:01:26.880 --> 00:01:29.160
Yeah, the import path is wrong.

18
00:01:29.360 --> 00:01:30.840
We need to go up one level.

19
00:01:32.020 --> 00:01:34.300
So that was generated incorrectly.

20
00:01:35.220 --> 00:01:40.920
And now, if I run that, looks better.

21
00:01:43.340 --> 00:01:47.820
Let's see whether it works by sending a request where we try to create an event.

22
00:01:49.020 --> 00:01:52.280
Or actually first, we can send a get request to get all events.

23
00:01:52.540 --> 00:01:55.360
We don't have any yet, but the request should work nonetheless.

24
00:01:55.700 --> 00:01:57.400
It just shouldn't return anything.

25
00:01:59.280 --> 00:02:06.240
So if I send a request, a get request to localhost 3000 slash events, I get back an empty array,

26
00:02:06.440 --> 00:02:07.740
which makes sense to me.

27
00:02:10.539 --> 00:02:14.740
Now let's send a post request to localhost 3000 events.

28
00:02:16.219 --> 00:02:18.800
And I get back an object with an event ID.

29
00:02:19.840 --> 00:02:25.100
I don't get back an error, even though I did not attach any data because I haven't added

30
00:02:25.100 --> 00:02:26.240
any validation yet.

31
00:02:26.640 --> 00:02:28.440
That's something we have yet to do.

32
00:02:29.700 --> 00:02:32.080
Currently, I don't validate anything.

33
00:02:32.340 --> 00:02:33.980
I create an event either way.

34
00:02:34.080 --> 00:02:38.280
And that at least seems to work because that event object was then also returned.

35
00:02:38.740 --> 00:02:40.020
It's this thing here.

36
00:02:41.720 --> 00:02:44.580
Now I won't test the other routes just yet.

37
00:02:44.700 --> 00:02:45.440
We'll do that later.

38
00:02:45.740 --> 00:02:49.920
But initially, it looks like everything's working and we can therefore now fine tune

39
00:02:49.920 --> 00:02:55.300
and tweak those controllers and make sure that we do really create the events the way

40
00:02:55.300 --> 00:02:56.460
we want them to create.

41
00:02:57.620 --> 00:02:59.480
And for example, we should also add validation.

