SoniYadav1234 / TodoProject

I developed Todo list project using Nodejs
0 stars 0 forks source link

Code refactoring #1

Open tsherdiwala opened 11 months ago

tsherdiwala commented 11 months ago

The following code seems to have many recurring things appearing:

File name: https://github.com/SoniYadav1234/TodoProject/blob/main/routes/todolist.js Link

const express = require('express');
const checkAuth = require('../Middleware/auth'); // importing middleware for authentication
const { readTodolist, createTodolist, updateTodolist, deleteTodolist, readAllTodolist } = require('../controller/todolist.js')
const route = express.Router();
route.get('/:id', checkAuth, readTodolist); // api to fetch data about single todo list item
route.get('/allTodolist', checkAuth, readAllTodolist); // api to fetch all todo list segregrated basis of user with pagination
route.post('/create', checkAuth,createTodolist); // api to create new item in todo list
route.put('/:id', checkAuth,updateTodolist); // api to update description or mark as done for task
route.delete('/:id', checkAuth,deleteTodolist); // api to delete todolist
module.exports = route;

Here I can see that checkAuth is being used at multiple places and is not able to keep the code DRY. Can we have some refactoring around this.

Also kindly revisit the corresponding user.js file as well which has similar issues.

SoniYadav1234 commented 11 months ago

Hi @tsherdiwala,

I've looked into the issue you raised. I'm happy to let you know that the issue has been resolved. The necessary changes have been made and committed to the repository. You can find the details in the following commit: commit link.

Thank you for bringing this to my attention and for your contribution to the project!

Best regards, Soni Yadav