So now in event.js I'm importing the database and I got a bunch of functions
which are exported to insert an event, update an event and so on. Now this is
all looking good so far. We'll have to test it anyways but it looks good on
first sight. We can now use these model functions in the events controller. So
now here I'll ask Copilot to insert functions or insert and export functions
for creating an event, editing an event, deleting an event and for getting one
event by ID or all events. Consider and I'll point at the event.js file in the
models folder so that it hopefully takes the functions that are exported there. It
looks like it does. Got a bunch of imports here from that file and then it
adds functions here to the controller file where I'm using the model functions
and send back appropriate responses. So that's looking good too and with that
we're extracting the request body. It renamed these functions from the model
file here and uses these aliases here in this file since it has equally named
functions create event and so on here which is fine. Alternatively what I'll do
here is I'll rename this to create, this to edit, this to delete item since delete
is a reserved name otherwise, get all and get single and with those names changed
I can get rid of these aliases here and that is something that probably would be
quicker with cursor since it's smart suggestion feature would probably allow
me to just hit tab a bunch of times and go through that file quicker. Here I have
to make all these changes manually which is a bit annoying but it is of course
also worth learning about these differences and of course things may
also change in the future. They very likely will but right now it was some
manual editing, some manual checks but now I got this events controller JS file
in place and it looks good thus far. Now we can go to the events routes here and
use the controller functions and for that I'll highlight the entire code here
and then ask Copilot to update the routes to use the appropriate controller
functions from and again just to be sure I'll point at my events controller
JS file here. Now let's see what that gives us.
So here we go the functions are imported from the events controller and then
they're used here in the routes and actually I'd like to make a little
change here. Import all controller functions through one single events
object so let's see whether it understands what I wanted to do. No, no, no,
no. So what I'll do is I'll accept this here, delete this part and this part and
because I want this import looking like this but then I want to use events dot
create simply because in my opinion that is a bit more readable. So events dot
edit, events dot delete item using the auto completion here like this and oh
well it did complete it down there. Yeah that makes no sense. Let's delete this.
So that's now the updated events routes file.