Skip to content

Task 3: Debug in Node.js#1

Open
spitaI wants to merge 10 commits intomasterfrom
task3
Open

Task 3: Debug in Node.js#1
spitaI wants to merge 10 commits intomasterfrom
task3

Conversation

@spitaI
Copy link
Owner

@spitaI spitaI commented May 18, 2021

Task 3. Debug in Node.js

Task description
Task check-list

Compl. Date Deadline
19.05.2021 23.05.2021

Примечание: Не очень понятен момент с указыванием номера строки с ошибкой (после рефакторинга эти строки могут сильно поменяться), поэтому, чтобы избежать путаницы, я буду указывать номера строк в исходном репозитории, опираясь на данное сообщение:

Screen Shot 2021-05-19 at 23 41 11

А также, для удобства, приводить ссылки на эти самые строки.
Кроме этого, я оставлял комментарии в коде над местами, где были ошибки, чтобы было понятней смотреть на отрефакторенный код.
А еще можно посмотреть историю коммитов по очереди, они специально сделаны практически атомарно.


Completion of checklist:

Compilation errors:
  1. ❌ Missing export of Sequelize instance
    ✅ Add export of Sequelize instance
    Line 16 (actually, you need to make a new line for it) at file db.js

  2. ❌ Missing export of Game model
    ✅ Add export of Game model
    Line 1 at file models/game.js

  3. ❌ The sequelize package was used for User model import
    ✅ Use Sequelize instance from db.js for User model import
    Line 2 at file middleware/validate-session.js

  4. ❌ Missing import of Express Router before usage
    ✅ Add import of Router from express package
    Line 1 at file controllers/usercontroller.js

  5. ❌ Incorrect package name when importing bcryptjs package
    ✅ Use bcryptjs instead of bcrypt for package name
    Line 2 at file controllers/usercontroller.js

  6. ❌ Incorrect variable name was used for export game router
    ✅ Use router instead of routers for variable name
    Line 116 at file controllers/gamecontroller.js

Logical errors:
  1. ❌ Incorrect usage of body-parser middleware
    ✅ Use .json() middleware of body-parser package
    Line 9 at file app.js

  2. ❌ Incorrect usage of validation middleware
    ✅ Use validation middleware only for game route
    Line 11 at file app.js

  3. ❌ PORT to listen on was not specified
    ✅ Use a port for app to listen on (e.g. 4000, like said in console.log)
    Line 13 at file app.js

  4. ❌ Incorrect property name for User model (passwordhash)
    ✅ Use name passwordHash instead
    Line 11 at file controllers/usercontroller.js

  5. ❌ Non-existing variable was used to pass games to response (games)
    ✅ Use variable data instead
    Line 9 at file controllers/gamecontroller.js

  6. ❌ User Id was taken from request body in Game POST handler (req.body.user.id)
    ✅ Use req.user.id instead, which is set up in validation middleware
    Line 42 at file controllers/gamecontroller.js

  7. ❌ Missing property id of req.user
    ✅ Add property id like req.user.id
    Line 73 at file controllers/gamecontroller.js

Refactoring:
  1. ✅ ES modules used instead of CommonJS
  2. ✅ Rewrited code in ES6 style (let/const, arrow functions, etc)
  3. .send() was replaced with .json() in responses containing object
  4. ✅ Corrected some response codes
  5. ✅ Rewrited Sequelize model import (bc of ESM)
  6. ✅ Added usage of dotenv package

@spitaI spitaI changed the title Task3 Task 3: Debug in Node.js May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant