So, we get some routes for accepting and deleting reservations, but of course there's no business
logic in there.
Now it would make sense to validate any submitted data, to make sure that a valid time and date
was submitted, a valid number of people, and to then maybe store that data in a database.
So what we could do is write another prompt here, refer to that file to be safe, though
it should normally consider the open file, but anyways, and then after adding this context
here say, validate the received input and store it in the database.
Now again, if I write it like this, that's very unspecific, so I'll get a reply, but
chances are that the reply is not really that great, that it's not really what I want.
And there also is another problem with this prompt here, it's not just not very specific,
it also asks for a lot.
I want to validate the received input and store it in a database, and both problems
are more or less complex.
For example, validating the input, I could add way more information here, which input
to validate, what to validate it for, so what my conditions, my criteria are.
And the same for a database, which database, which data should get stored there, and so
on.
So this is a short prompt for a complex problem, and you want to avoid prompts like this.
You want to split them up into multiple problems and into multiple prompts instead, typically.
Because here I'm getting back some code, but I'm not sure if it's really the code I
want.
And indeed here, if you take a closer look at the code it generated here, you can see
that regarding that database storage part, it did not generate any code for that.
It just assumes that there is a reservation model in a models folder in a reservation
file, but that's a file you would have to create, and that's a model you would have
to create as well.
It does not exist here in this project.
So it assumes that this is there, and that this then will store the data in the database.
So if you just apply this code and run it, it simply won't work.
It also assumes that the express validator package is installed, which is also not the
case.
So as you can tell, here it generated some code, which wouldn't work, which would require
a couple of extra steps that are not mentioned here in the response.
And that's why you want to avoid unspecific, complex, multi-problem prompts like this typically.
Instead you can open a new chat, or use the inline chat here actually, and select this
code here, because ultimately that's what I want to validate.
And then just say add code to validate this input.
Don't use an external library.
Number of people should be between 1 and 6, let's say.
Time should be between 5 p.m. and let's say 11 p.m., only every 30 minutes.
Date should be today or in the future.
And now I'll actually add some extra examples regarding the time, because what I want to
allow is that people can book 5 p.m. or 5.30, 6 p.m. or 6.30, but not quarter past five
or 5.10 or anything like that.
So I'll add some extra examples regarding the time.
People should be allowed to book 5, 5.30, 6, 6.30, and so on, but not 5.10, 5.15, etc.
So I'm adding some examples here to add more context in the end to the prompt to hopefully
get exactly the code I'm looking for.
So let's hit enter, and this is a rather complex task now, so let's see what it generates.
Generates a bunch of code and looks like it's done.
So what it's doing here is still extracting.
the data from the body, then it's checking the number of people, if it's
not a number or if it's a number smaller than one or greater than six in
which case it returns an error response, then it validates the time and here it
simply hardcodes the available time slots which I guess makes sense because
it really isn't that many 5 p.m. till 11 p.m. so it does that in the 24-hour
format which is fine by me and then it checks whether the valid times array
includes the time that was submitted with the request and if that's not the
case it will return an error response and for the date it gets the current
date and converts the received date to a date object and then it sets the hours
of today to the start of the day and then checks if the timestamp in
milliseconds of the input date is maybe not a number or if it's smaller than
today if the input data is smaller than today and in either case it sends back a
response. Now we should definitely test this code to make sure it really works
the way it should but it looks good to me so I'll accept this and this shows
you how now we got a vastly different code than what I had before in the chat
so this is what it generated before it just assumed that there was some
validation library and it also ran different kinds of validation now we get
a much better result because we were more specific we added specific useful
context and we added examples and that's why prompt engineering matters once you
know it it's obvious but it's easy to forget or to not even be aware of the
importance of being specific of providing examples and of really
controlling which kinds of results the AI will generate for you