WEBVTT

1
00:00:01.539 --> 00:00:06.240
So now in event.js I'm importing the database and I got a bunch of functions

2
00:00:06.240 --> 00:00:13.880
which are exported to insert an event, update an event and so on. Now this is

3
00:00:13.880 --> 00:00:18.860
all looking good so far. We'll have to test it anyways but it looks good on

4
00:00:18.860 --> 00:00:26.960
first sight. We can now use these model functions in the events controller. So

5
00:00:26.880 --> 00:00:36.380
now here I'll ask Copilot to insert functions or insert and export functions

6
00:00:36.380 --> 00:00:48.060
for creating an event, editing an event, deleting an event and for getting one

7
00:00:48.480 --> 00:00:58.900
event by ID or all events. Consider and I'll point at the event.js file in the

8
00:00:58.900 --> 00:01:04.099
models folder so that it hopefully takes the functions that are exported there. It

9
00:01:04.099 --> 00:01:08.400
looks like it does. Got a bunch of imports here from that file and then it

10
00:01:08.400 --> 00:01:13.320
adds functions here to the controller file where I'm using the model functions

11
00:01:13.360 --> 00:01:21.620
and send back appropriate responses. So that's looking good too and with that

12
00:01:21.620 --> 00:01:28.800
we're extracting the request body. It renamed these functions from the model

13
00:01:29.640 --> 00:01:34.880
file here and uses these aliases here in this file since it has equally named

14
00:01:34.880 --> 00:01:41.560
functions create event and so on here which is fine. Alternatively what I'll do

15
00:01:41.520 --> 00:01:52.360
here is I'll rename this to create, this to edit, this to delete item since delete

16
00:01:52.360 --> 00:02:04.100
is a reserved name otherwise, get all and get single and with those names changed

17
00:02:04.100 --> 00:02:09.520
I can get rid of these aliases here and that is something that probably would be

18
00:02:09.479 --> 00:02:15.780
quicker with cursor since it's smart suggestion feature would probably allow

19
00:02:15.780 --> 00:02:22.580
me to just hit tab a bunch of times and go through that file quicker. Here I have

20
00:02:22.580 --> 00:02:28.760
to make all these changes manually which is a bit annoying but it is of course

21
00:02:28.760 --> 00:02:33.320
also worth learning about these differences and of course things may

22
00:02:33.320 --> 00:02:38.680
also change in the future. They very likely will but right now it was some

23
00:02:38.680 --> 00:02:43.500
manual editing, some manual checks but now I got this events controller JS file

24
00:02:43.500 --> 00:02:51.680
in place and it looks good thus far. Now we can go to the events routes here and

25
00:02:51.680 --> 00:02:55.460
use the controller functions and for that I'll highlight the entire code here

26
00:02:56.900 --> 00:03:03.540
and then ask Copilot to update the routes to use the appropriate controller

27
00:03:05.700 --> 00:03:12.300
functions from and again just to be sure I'll point at my events controller

28
00:03:12.300 --> 00:03:17.540
JS file here. Now let's see what that gives us.

29
00:03:19.500 --> 00:03:29.180
So here we go the functions are imported from the events controller and then

30
00:03:29.180 --> 00:03:32.200
they're used here in the routes and actually I'd like to make a little

31
00:03:32.120 --> 00:03:42.660
change here. Import all controller functions through one single events

32
00:03:42.660 --> 00:03:52.140
object so let's see whether it understands what I wanted to do. No, no, no,

33
00:03:52.280 --> 00:04:02.100
no. So what I'll do is I'll accept this here, delete this part and this part and

34
00:04:01.940 --> 00:04:07.440
because I want this import looking like this but then I want to use events dot

35
00:04:07.440 --> 00:04:14.020
create simply because in my opinion that is a bit more readable. So events dot

36
00:04:14.020 --> 00:04:24.720
edit, events dot delete item using the auto completion here like this and oh

37
00:04:24.720 --> 00:04:29.340
well it did complete it down there. Yeah that makes no sense. Let's delete this.

38
00:04:30.760 --> 00:04:34.740
So that's now the updated events routes file.

