WEBVTT

1
00:00:01.859 --> 00:00:07.880
So, of course now we got authorization added, finally it's now also time to make sure

2
00:00:07.880 --> 00:00:11.540
that we can also register for events and not just create them.

3
00:00:12.700 --> 00:00:17.900
Hence we need more event-related routes and for that I'll go to the events.js file in

4
00:00:17.900 --> 00:00:18.840
the routes folder.

5
00:00:20.040 --> 00:00:26.220
And here I want to add more routes like a post route which can be used for signing up

6
00:00:27.720 --> 00:00:34.280
and again, thankfully, GitHub Copilot is pretty smart here and it suggests a route which makes

7
00:00:34.280 --> 00:00:37.480
a lot of sense, though I'll name it register, not attend.

8
00:00:38.880 --> 00:00:43.700
And this attend function on the events controller object doesn't exist yet, but I'll add

9
00:00:43.700 --> 00:00:44.160
it soon.

10
00:00:45.280 --> 00:00:50.760
I'll also enter a new line so that GitHub Copilot suggests the unregister route which

11
00:00:50.760 --> 00:00:51.340
looks good.

12
00:00:52.800 --> 00:00:59.520
And now I just need to add a register and unregister controller function to the event

13
00:00:59.520 --> 00:01:03.060
controller, so to the events controller.js file.

14
00:01:04.620 --> 00:01:12.500
So in there at the bottom, I'll just place my cursor here, wait a couple of seconds and

15
00:01:12.500 --> 00:01:19.440
again, since GitHub Copilot tries to keep your last actions in mind and keep it in its

16
00:01:19.480 --> 00:01:25.480
context, so to say, I get a good suggestion here, a function named register, which is

17
00:01:25.480 --> 00:01:30.700
exported, which seems to do the job I want it to do.

18
00:01:31.020 --> 00:01:36.140
It extracts the ID from the request parameters, finds the event with that ID.

19
00:01:36.620 --> 00:01:38.900
If there is no such event, it returns an error.

20
00:01:40.540 --> 00:01:45.760
Otherwise it tries to insert an entry in the registrations table, which we have yet to

21
00:01:45.720 --> 00:01:52.900
set up, but it tries to enter an entry there where we have basically a combination of event

22
00:01:52.900 --> 00:01:54.140
ID and user ID.

23
00:01:55.880 --> 00:02:01.520
And that is essentially a registration, a certain user registered for a certain event.

24
00:02:03.390 --> 00:02:06.240
Then this is executed and then we get different responses.

25
00:02:07.889 --> 00:02:10.520
Now we also need an unregister function.

26
00:02:10.699 --> 00:02:12.780
Let's see if this is suggested as well.

27
00:02:14.000 --> 00:02:16.240
Yep, looks like it is for me here.

28
00:02:16.880 --> 00:02:23.160
If it's not, you can of course simply start typing unreg and at some point it should be

29
00:02:23.160 --> 00:02:32.260
suggested and here we do almost the same as before, but we delete a registration by the

30
00:02:32.260 --> 00:02:34.960
event ID user ID combination here.

31
00:02:37.280 --> 00:02:40.280
And the user ID is retrieved from the request.

32
00:02:41.760 --> 00:02:47.440
And it should be available there because in the routes file, the authenticate middleware

33
00:02:47.440 --> 00:02:48.840
is added here as well.

34
00:02:50.060 --> 00:02:53.660
And that does extract the user ID from the attached token.

35
00:02:54.880 --> 00:03:00.140
So that should work, but of course we must make sure that the appropriate database table

36
00:03:00.140 --> 00:03:00.760
is set up.

37
00:03:02.329 --> 00:03:09.760
So for that, I'll go to the database.js file and here where I set up the other tables,

38
00:03:10.560 --> 00:03:14.360
I'll enter a new line and see if I got some suggestions.

39
00:03:15.240 --> 00:03:16.900
If not, I'll start typing.

40
00:03:19.619 --> 00:03:22.100
Create table if not exists registrations.

41
00:03:22.500 --> 00:03:23.920
Sure, let's go step by step.

42
00:03:24.340 --> 00:03:24.920
Here we go.

43
00:03:25.899 --> 00:03:27.920
Let's accept this and this looks good to me.

44
00:03:29.400 --> 00:03:34.000
Event ID, user ID, both are foreign keys pointing to other tables.

45
00:03:34.420 --> 00:03:35.660
That looks good.

46
00:03:36.920 --> 00:03:42.420
To make sure that this is really executed, you can restart the server, though it should

47
00:03:42.420 --> 00:03:45.220
be picked up automatically due to watch mode normally.

48
00:03:47.700 --> 00:03:51.640
With that done, you should be able to send those registration requests.

