Conversation
…to separate functions
|
I would also live a comment what to do:
Done. |
| }, | ||
| "dependencies": { | ||
| "express": "^4.18.2", | ||
| "uuid": "^9.0.0" |
There was a problem hiding this comment.
It always best to rely on standard modules if possible i.e modules you get from nodejs in this case. Node has this inbuilt https://nodejs.org/api/crypto.html#cryptorandomuuidoptions
const { randomUUID } = require('crypto');;
Then use randomUUID() to generate random uuid.
| } | ||
|
|
||
| const newId = Math.max(...todos.map((todo) => todo.id)) + 1; | ||
| const newTodo = new Todo(newId, `Title ${newId}`, false); |
There was a problem hiding this comment.
This restrict todo to Title and random id... what if user wants to save their own todo ?
You should capture the values for create Todo from req.body. So if call endpoint
POST /todos and send something like { title: 'I am learning express and nodejs' } ... that sould be persisted.
There was a problem hiding this comment.
Also since first time you create todo... its obvious its not completed and id should be auto generated coz users do not care about that,...they just provide title of todo and done.
so when create todo... using the https://github.com/yulsmir/todo-express-api/pull/1/files#r1209546591, you could have body of request to be like
{ id: randomUUID(), title: req.body.title, completed: false }
Then you won't need this part const newId = Math.max(...todos.map((todo) => todo.id)) + 1;
Implement server using express module