WEBVTT

1
00:00:02.100 --> 00:00:07.840
Now what I don't like regarding these or about these suggestions is for one that it

2
00:00:07.840 --> 00:00:10.320
creates a bunch of methods in objects.

3
00:00:11.360 --> 00:00:17.220
You could use this approach, you could also work with classes, there's absolutely nothing

4
00:00:17.220 --> 00:00:22.120
wrong with that, but here I actually just want to have some plain simple functions being

5
00:00:22.120 --> 00:00:23.300
created and exported.

6
00:00:24.760 --> 00:00:28.020
And speaking of exports, that's another thing I don't like.

7
00:00:28.560 --> 00:00:35.700
I don't want to use this common JS export style, which this style here is called, and

8
00:00:35.700 --> 00:00:38.420
which is reflected in this import style.

9
00:00:38.900 --> 00:00:44.740
Instead I want to use the more modern ESM imports and exports style.

10
00:00:45.620 --> 00:00:50.120
Now if that doesn't tell you anything that's not too important, the main thing to take

11
00:00:50.120 --> 00:00:56.480
away here is that Node.js essentially offers you two different syntaxes for importing and

12
00:00:56.480 --> 00:01:01.220
exporting stuff, and I want to use the more modern syntax, which this one here is not.

13
00:01:02.760 --> 00:01:07.860
So I'll send some follow-up feedback to Composer and to Cursor therefore.

14
00:01:08.780 --> 00:01:11.380
And I'll break it up into two pieces actually.

15
00:01:11.520 --> 00:01:14.880
And I'll start with the thing that I don't want to have methods in objects.

16
00:01:16.380 --> 00:01:27.220
I don't want to have methods in objects like the create method in the user object.

17
00:01:28.140 --> 00:01:35.780
Instead simply export and import a bunch of standalone functions.

18
00:01:36.140 --> 00:01:39.020
Do that in all files.

19
00:01:41.180 --> 00:01:47.200
So that's the first feedback I have, and I'll see if Cursor adjusts the code accordingly.

20
00:01:48.720 --> 00:01:49.780
Yeah, it looks good.

21
00:01:50.260 --> 00:01:57.300
It has a createUser function now, which receives some user data, and then does nothing with

22
00:01:57.300 --> 00:02:01.760
it because I told it earlier that I don't want the actual code for putting it into a

23
00:02:01.760 --> 00:02:09.479
database just yet, and it has the findUserByEmail function here, which it also thinks it will

24
00:02:10.300 --> 00:02:11.640
need later on.

25
00:02:11.740 --> 00:02:15.260
Now we will need more functions actually, but okay, it's a start.

26
00:02:16.580 --> 00:02:24.040
So then we got the controller, and there it's now also separate functions, which are exposed

27
00:02:24.040 --> 00:02:24.420
here.

28
00:02:26.240 --> 00:02:31.460
And yeah, I guess since it has all the login logic here, and it uses the findUserByEmail

29
00:02:31.460 --> 00:02:36.140
function here, we might be fine with just having that function on the user model actually.

30
00:02:36.260 --> 00:02:37.440
But we can always tweak that.

31
00:02:39.220 --> 00:02:41.920
So that's not looking too bad here.

32
00:02:43.100 --> 00:02:46.540
As a next step, I can therefore change this import-export syntax.

33
00:02:48.320 --> 00:02:57.280
Change the import-export syntax across all files from common.js to ESM.

34
00:02:59.120 --> 00:03:04.720
That's my next feedback for Cursor because, well, that is the syntax I want to have.

35
00:03:05.480 --> 00:03:10.720
So it goes ahead, rewrites all these functions, but now it does indeed export them with that

36
00:03:10.720 --> 00:03:13.840
more modern syntax and also uses it for importing.

37
00:03:15.820 --> 00:03:17.420
So that's looking good.

38
00:03:17.900 --> 00:03:22.240
In the package.js file, it wants to set the type to module, but I think I already did

39
00:03:22.240 --> 00:03:22.620
that.

40
00:03:23.300 --> 00:03:26.920
Yeah, I already have that in there, so no need to do that.

41
00:03:28.280 --> 00:03:33.460
And gitignore, yeah, I also pretty much had that, so not sure why it's doing that here.

42
00:03:33.840 --> 00:03:35.980
But in general, this all looks good.

43
00:03:37.519 --> 00:03:42.700
So therefore, I'll hit accept here to accept the user.js file.

44
00:03:43.220 --> 00:03:46.020
Do the same here for users.js.

45
00:03:46.460 --> 00:03:47.860
I'm also happy with that.

46
00:03:49.540 --> 00:03:52.800
For the users.controller.js file, I'll also accept this.

47
00:03:53.160 --> 00:03:57.680
And I could use the shortcut, which is shown here too, of course, but I'll do it manually.

48
00:03:59.880 --> 00:04:04.560
And then no changes are needed for the package.js file, so I'll actually reject that here.

49
00:04:05.040 --> 00:04:09.600
And for gitignore, yeah, I mean, sure, we can add the slash here at the end.

50
00:04:09.980 --> 00:04:11.360
So I'll accept this.

51
00:04:12.640 --> 00:04:20.380
And with that, we can close this composer window, close all these windows, and now we

52
00:04:20.380 --> 00:04:21.519
got a bunch of files here.

53
00:04:22.560 --> 00:04:27.480
Now I will actually rename some of these files because I like to have a different naming

54
00:04:27.480 --> 00:04:32.520
convention here, but I won't do that with AI, but instead manually because that's one

55
00:04:32.520 --> 00:04:35.720
of these tasks, which is probably quicker.

56
00:04:35.920 --> 00:04:42.640
I'm quicker if I do it manually instead of telling AI to do it if I know exactly what

57
00:04:42.640 --> 00:04:43.260
I want to do.

58
00:04:44.280 --> 00:04:45.660
Yeah, I'm actually already done.

59
00:04:45.740 --> 00:04:47.140
This was the only change I wanted.

60
00:04:47.620 --> 00:04:52.620
In addition, instead of exporting these functions like this, and instead of creating them with

61
00:04:52.640 --> 00:04:59.260
const, which I could do, I'll also change this here and I'll use the function keyword

62
00:04:59.260 --> 00:04:59.560
here.

63
00:05:01.440 --> 00:05:05.240
like this, and now I'm getting a suggestion here,

64
00:05:05.420 --> 00:05:08.840
but hard to see, which I can accept.

65
00:05:08.980 --> 00:05:10.560
It added the export keyword,

66
00:05:10.860 --> 00:05:12.160
but actually that's not what I wanted.

67
00:05:12.360 --> 00:05:15.580
Instead, I want to export a function called createUser,

68
00:05:16.760 --> 00:05:21.680
and now it should change this code here to use this syntax.

69
00:05:22.320 --> 00:05:24.400
Looks like it's making the right suggestions.

70
00:05:25.200 --> 00:05:27.320
It's highlighted in red here that it

71
00:05:27.320 --> 00:05:29.660
wants to remove the equal sign at the arrow here,

72
00:05:29.840 --> 00:05:32.600
which will change this arrow function syntax,

73
00:05:32.720 --> 00:05:35.900
which it had before, and which it has down here,

74
00:05:36.040 --> 00:05:38.460
which is one way of defining functions in JavaScript

75
00:05:38.460 --> 00:05:41.680
to that alternative syntax with the function keyword,

76
00:05:41.860 --> 00:05:42.400
which I prefer.

77
00:05:43.000 --> 00:05:44.460
So I'll just hit tab here,

78
00:05:45.200 --> 00:05:46.800
and that's a quick way of migrating it,

79
00:05:47.000 --> 00:05:49.260
and now cursor's autocompletion

80
00:05:49.260 --> 00:05:51.620
and suggestions magic really kicks in

81
00:05:52.360 --> 00:05:54.620
because it now makes the same suggestion

82
00:05:54.620 --> 00:05:58.240
for this second function, the findUserByEmail function,

83
00:05:59.040 --> 00:06:01.120
understanding what I'm aiming to do here,

84
00:06:01.300 --> 00:06:02.920
and therefore really speeding me up

85
00:06:03.740 --> 00:06:06.940
because now by simply hitting tab again and again,

86
00:06:07.240 --> 00:06:10.900
it converts this code to also use the function keyword

87
00:06:10.900 --> 00:06:13.200
and to have the export keyword in front of it,

88
00:06:13.800 --> 00:06:16.520
which is just a different way of writing this code,

89
00:06:16.600 --> 00:06:17.720
but the way I want to use,

90
00:06:18.060 --> 00:06:20.640
and as you saw, because I made some minor changes

91
00:06:20.640 --> 00:06:21.760
to the first function,

92
00:06:21.920 --> 00:06:23.720
it helped me complete those changes

93
00:06:23.720 --> 00:06:27.020
and then suggested the same changes for the second function,

94
00:06:27.400 --> 00:06:29.800
which therefore can speed up development.

95
00:06:31.280 --> 00:06:32.600
So that's great.

96
00:06:33.080 --> 00:06:35.180
In the user's controller.js file,

97
00:06:35.260 --> 00:06:36.520
I want to make the same changes.

98
00:06:37.920 --> 00:06:42.120
Here, export is actually already in front of the function,

99
00:06:42.280 --> 00:06:44.580
but I want to switch from this arrow function syntax

100
00:06:44.580 --> 00:06:47.020
to use the function keyword instead.

101
00:06:48.380 --> 00:06:51.560
Again, it's making the appropriate suggestions here,

102
00:06:51.640 --> 00:06:54.200
and then I can tab, tab, tab

103
00:06:54.600 --> 00:06:57.620
to also convert the other function down there.

104
00:06:57.860 --> 00:06:58.659
So that's awesome.

105
00:07:00.720 --> 00:07:04.600
And with that, I got the initial basic code I want

106
00:07:04.600 --> 00:07:06.240
for a user registration,

107
00:07:06.940 --> 00:07:09.919
and we can now take the next steps together with AI

108
00:07:09.919 --> 00:07:12.020
and our knowledge as a developer.

