tieme-ndo/backend

View on GitHub

Showing 61 of 61 total issues

Function updateFarmer has 110 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const updateFarmer = async (req, res, next) => {
  try {
    const farmerId = req.params.id;
    const farmerDetails = req.body;
    const { username, isAdmin } = req.user;
Severity: Major
Found in controllers/farmer/updateFarmer.js - About 4 hrs to fix

    Function updateFarmer has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

    const updateFarmer = async (req, res, next) => {
      try {
        const farmerId = req.params.id;
        const farmerDetails = req.body;
        const { username, isAdmin } = req.user;
    Severity: Minor
    Found in controllers/farmer/updateFarmer.js - About 4 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function approveChangeRequest has 51 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const approveChangeRequest = async (req, res, next) => {
      try {
        const changeRequestEntry = await models.ChangeRequest.findOne({
          _id: req.params.id
        });
    Severity: Major
    Found in controllers/changeRequest/approveChangeRequest.js - About 2 hrs to fix

      Function resetPassword has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const resetPassword = async (req, res, next) => {
        try {
          const userExist = await models.User.findOne({
            username: req.user.username
          }).lean();
      Severity: Minor
      Found in controllers/user/resetPassword.js - About 1 hr to fix

        Function getChangeRequestById has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const getChangeRequestById = async (req, res, next) => {
          try {
            const changeRequest = await models.ChangeRequest.findOne({
              _id: req.params.id
            }).lean();
        Severity: Minor
        Found in controllers/changeRequest/getChangeRequests.js - About 1 hr to fix

          Function login has 39 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const login = async (req, res, next) => {
            try {
              let { username } = req.body;
              const { password } = req.body;
              username = username.toLowerCase();
          Severity: Minor
          Found in controllers/user/login.js - About 1 hr to fix

            Function deleteFarmer has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const deleteFarmer = async (req, res, next) => {
              try {
                const farmerId = req.params.id;
                const { isAdmin } = req.user;
            
            
            Severity: Minor
            Found in controllers/farmer/deleteFarmer.js - About 1 hr to fix

              Function getStatistics has 35 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const getStatistics = async (req, res, next) => {
                try {
                  const allFarmers = await models.Farmer.find({ archived: false });
              
                  const totalNumOfFarmers = allFarmers.length;
              Severity: Minor
              Found in controllers/farmer/statistics.js - About 1 hr to fix

                Function addFarmer has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const addFarmer = async (req, res, next) => {
                  try {
                    const farmerDetails = req.body;
                    const { username } = req.user;
                
                
                Severity: Minor
                Found in controllers/farmer/addFarmer.js - About 1 hr to fix

                  Function register has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const register = async (req, res, next) => {
                    try {
                      const userDetails = req.body;
                  
                      const salt = bcrypt.genSaltSync(10);
                  Severity: Minor
                  Found in controllers/user/register.js - About 1 hr to fix

                    Function getAllChangeRequests has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const getAllChangeRequests = async (req, res, next) => {
                      try {
                        const nonRequestedDataFields = {
                          requested_changes: false
                        };
                    Severity: Minor
                    Found in controllers/changeRequest/getChangeRequests.js - About 1 hr to fix

                      Avoid too many return statements within this function.
                      Open

                            return res.status(201).json({
                              success: true,
                              message: 'Farmer details updated successfully',
                              farmer: updatedFarmer
                            });
                      Severity: Major
                      Found in controllers/farmer/updateFarmer.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                            return next(
                              createError({
                                message: 'Could not update farmer details',
                                status: GENERIC_ERROR
                              })
                        Severity: Major
                        Found in controllers/farmer/updateFarmer.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                              return res.status(201).json({
                                success: true,
                                message: 'Your change was created and is ready for admin approval',
                                farmerEditRequest
                              });
                          Severity: Major
                          Found in controllers/farmer/updateFarmer.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                return next(
                                  createError({
                                    message: 'Internal database error',
                                    status: GENERIC_ERROR
                                  })
                            Severity: Major
                            Found in controllers/changeRequest/approveChangeRequest.js - About 30 mins to fix

                              Function approveChangeRequest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                              Open

                              const approveChangeRequest = async (req, res, next) => {
                                try {
                                  const changeRequestEntry = await models.ChangeRequest.findOne({
                                    _id: req.params.id
                                  });
                              Severity: Minor
                              Found in controllers/changeRequest/approveChangeRequest.js - About 25 mins to fix

                              Cognitive Complexity

                              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                              A method's cognitive complexity is based on a few simple rules:

                              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                              • Code is considered more complex for each "break in the linear flow of the code"
                              • Code is considered more complex when "flow breaking structures are nested"

                              Further reading

                              Parsing error: Invalid ecmaVersion.
                              Open

                              const jwt = require('jsonwebtoken');
                              Severity: Minor
                              Found in helpers/generateToken.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Parsing error: Invalid ecmaVersion.
                              Open

                              /* eslint-disable max-len */
                              Severity: Minor
                              Found in controllers/user/resetPassword.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Parsing error: Invalid ecmaVersion.
                              Open

                              const express = require('express');
                              Severity: Minor
                              Found in routes/changeRequestRouter.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Parsing error: Invalid ecmaVersion.
                              Open

                              const { UNAUTHORIZED } = require('../../helpers/error');
                              Severity: Minor
                              Found in middlewares/errors/unauthorized.js by eslint

                              For more information visit Source: http://eslint.org/docs/rules/

                              Severity
                              Category
                              Status
                              Source
                              Language