Now what I don't like regarding these or about these suggestions is for one that it
creates a bunch of methods in objects.
You could use this approach, you could also work with classes, there's absolutely nothing
wrong with that, but here I actually just want to have some plain simple functions being
created and exported.
And speaking of exports, that's another thing I don't like.
I don't want to use this common JS export style, which this style here is called, and
which is reflected in this import style.
Instead I want to use the more modern ESM imports and exports style.
Now if that doesn't tell you anything that's not too important, the main thing to take
away here is that Node.js essentially offers you two different syntaxes for importing and
exporting stuff, and I want to use the more modern syntax, which this one here is not.
So I'll send some follow-up feedback to Composer and to Cursor therefore.
And I'll break it up into two pieces actually.
And I'll start with the thing that I don't want to have methods in objects.
I don't want to have methods in objects like the create method in the user object.
Instead simply export and import a bunch of standalone functions.
Do that in all files.
So that's the first feedback I have, and I'll see if Cursor adjusts the code accordingly.
Yeah, it looks good.
It has a createUser function now, which receives some user data, and then does nothing with
it because I told it earlier that I don't want the actual code for putting it into a
database just yet, and it has the findUserByEmail function here, which it also thinks it will
need later on.
Now we will need more functions actually, but okay, it's a start.
So then we got the controller, and there it's now also separate functions, which are exposed
here.
And yeah, I guess since it has all the login logic here, and it uses the findUserByEmail
function here, we might be fine with just having that function on the user model actually.
But we can always tweak that.
So that's not looking too bad here.
As a next step, I can therefore change this import-export syntax.
Change the import-export syntax across all files from common.js to ESM.
That's my next feedback for Cursor because, well, that is the syntax I want to have.
So it goes ahead, rewrites all these functions, but now it does indeed export them with that
more modern syntax and also uses it for importing.
So that's looking good.
In the package.js file, it wants to set the type to module, but I think I already did
that.
Yeah, I already have that in there, so no need to do that.
And gitignore, yeah, I also pretty much had that, so not sure why it's doing that here.
But in general, this all looks good.
So therefore, I'll hit accept here to accept the user.js file.
Do the same here for users.js.
I'm also happy with that.
For the users.controller.js file, I'll also accept this.
And I could use the shortcut, which is shown here too, of course, but I'll do it manually.
And then no changes are needed for the package.js file, so I'll actually reject that here.
And for gitignore, yeah, I mean, sure, we can add the slash here at the end.
So I'll accept this.
And with that, we can close this composer window, close all these windows, and now we
got a bunch of files here.
Now I will actually rename some of these files because I like to have a different naming
convention here, but I won't do that with AI, but instead manually because that's one
of these tasks, which is probably quicker.
I'm quicker if I do it manually instead of telling AI to do it if I know exactly what
I want to do.
Yeah, I'm actually already done.
This was the only change I wanted.
In addition, instead of exporting these functions like this, and instead of creating them with
const, which I could do, I'll also change this here and I'll use the function keyword
here.
like this, and now I'm getting a suggestion here,
but hard to see, which I can accept.
It added the export keyword,
but actually that's not what I wanted.
Instead, I want to export a function called createUser,
and now it should change this code here to use this syntax.
Looks like it's making the right suggestions.
It's highlighted in red here that it
wants to remove the equal sign at the arrow here,
which will change this arrow function syntax,
which it had before, and which it has down here,
which is one way of defining functions in JavaScript
to that alternative syntax with the function keyword,
which I prefer.
So I'll just hit tab here,
and that's a quick way of migrating it,
and now cursor's autocompletion
and suggestions magic really kicks in
because it now makes the same suggestion
for this second function, the findUserByEmail function,
understanding what I'm aiming to do here,
and therefore really speeding me up
because now by simply hitting tab again and again,
it converts this code to also use the function keyword
and to have the export keyword in front of it,
which is just a different way of writing this code,
but the way I want to use,
and as you saw, because I made some minor changes
to the first function,
it helped me complete those changes
and then suggested the same changes for the second function,
which therefore can speed up development.
So that's great.
In the user's controller.js file,
I want to make the same changes.
Here, export is actually already in front of the function,
but I want to switch from this arrow function syntax
to use the function keyword instead.
Again, it's making the appropriate suggestions here,
and then I can tab, tab, tab
to also convert the other function down there.
So that's awesome.
And with that, I got the initial basic code I want
for a user registration,
and we can now take the next steps together with AI
and our knowledge as a developer.