-
-
Notifications
You must be signed in to change notification settings - Fork 444
London10_Jan_Softa_Node.js_Week2_CYF_Chat_Server #289
base: master
Are you sure you want to change the base?
Conversation
giorgiguts
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work! You've clearly demonstrated that you understand core concepts of AJAX calls, CRUD operations and the fundamentals of building effective Restful APIs. Keep up the great work! 😊
| <script> | ||
| function deleteMessage() { | ||
| const idToDelete = document.getElementById("deleteId").value; | ||
| if (!idToDelete || isNaN(idToDelete)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of a guard clause! 🥳 it's very important to have these layers of security throughout our codebase, to minimise the amount of bugs, and stop our program from crashing. Excellent work!
| <button type="button" onclick="deleteMessage()">Submit</button> | ||
| </form> | ||
|
|
||
| <script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a suggestion, we can create a separate javascript file, for example script.js and then refer or include that exact javascript file into the script HTML element. You can read more on that here for example. This way, we can effectively structure our code.
| fetch(url, { | ||
| method: "DELETE", | ||
| }) | ||
| .then((response) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, as a suggestion and going forward with JavaScript, is to get acquainted with ES6+ features and apply them to your JS solutions. One of the ES6+ features (which generally means modern JavaScript) is the use of async/await functions. There's this amazing instructor Colt Steele out there on Youtube, and I highly suggest you watch this tutorial on how to use it, here's the link. He has really comprehensive and easy-to-follow tutorials on his Youtube channel. 10/10 recommended 🥹
The idea of using async/await is to make your codebase shorter and thus easier to understand. 😊
| app.get("/messages/:id", (req, res) => { | ||
| const getById = Number(req.params.id); | ||
| const findByID = messages.find((message) => message.id === getById); | ||
| if (!findByID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, excellent use of a guard clause! 🥳
| const { from, text } = req.body; | ||
|
|
||
| // Check if the 'from' and 'text' properties are present and not empty | ||
| if (!from || !text || from.trim() === "" || text.trim() === "") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very smart. Just because we don't have power over what user may type, we are anticipating and trimming any excess whitespace. Great work 💪
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?