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;
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;
- Read upRead up
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
});
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();
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();
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();
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;
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;
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;
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);
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
};
Avoid too many return
statements within this function. Open
return res.status(201).json({
success: true,
message: 'Farmer details updated successfully',
farmer: updatedFarmer
});
Avoid too many return
statements within this function. Open
return next(
createError({
message: 'Could not update farmer details',
status: GENERIC_ERROR
})
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
});
Avoid too many return
statements within this function. Open
return next(
createError({
message: 'Internal database error',
status: GENERIC_ERROR
})
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
});
- Read upRead up
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');
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Parsing error: Invalid ecmaVersion. Open
/* eslint-disable max-len */
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Parsing error: Invalid ecmaVersion. Open
const express = require('express');
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Parsing error: Invalid ecmaVersion. Open
const { UNAUTHORIZED } = require('../../helpers/error');
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/