unicef/magicbox-open-api

View on GitHub

Showing 12 of 22 total issues

File general.js has 478 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import config from '../../config'
import bluebird from 'bluebird'
import PostgresHelper from './postgres'
import * as data_access from '../../utils/data_access'
import fs from 'fs'
Severity: Minor
Found in api/helpers/general.js - About 7 hrs to fix

    Function getProperties has 87 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const getProperties = (queryString) => {
      return new Promise((resolve, reject) => {
        let queryParts = queryString.split('_')
        let key = queryParts[0]
        let path = ''
    Severity: Major
    Found in api/helpers/general.js - About 3 hrs to fix

      Function getProperties has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      export const getProperties = (queryString) => {
        return new Promise((resolve, reject) => {
          let queryParts = queryString.split('_')
          let key = queryParts[0]
          let path = ''
      Severity: Minor
      Found in api/helpers/general.js - About 2 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 getUserInfo has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      export const getUserInfo = (token) => {
        return new Promise((resolve, reject) => {
          console.log('Check if user has been seen')
          if (user_seen(token)) {
            console.log('No need to hit Auth0')
      Severity: Minor
      Found in api/helpers/auth.js - About 2 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 verifyToken has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const verifyToken = (req, authOrSecDef, token, callback) => {
        let errorObject = {message: 'Access Denied. Please check your token'}
      
        if (token && token.indexOf(tokenPrefix) !== -1) {
          let accessToken = token.substring(
      Severity: Major
      Found in api/helpers/auth.js - About 2 hrs to fix

        Function buildWhere has 50 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          buildWhere(params) {
            let group_by = null;
            if (params.group_by) {
              group_by = params.group_by;
              delete params.group_by
        Severity: Minor
        Found in api/helpers/postgres.js - About 2 hrs to fix

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

          const mergePropertiesWithShapefile = (shapefileSet) => {
            return new Promise((resolve, reject) => {
              let {
                kind,
                source: dir,
          Severity: Minor
          Found in api/helpers/general.js - About 1 hr to fix

            Function getUserInfo has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const getUserInfo = (token) => {
              return new Promise((resolve, reject) => {
                console.log('Check if user has been seen')
                if (user_seen(token)) {
                  console.log('No need to hit Auth0')
            Severity: Minor
            Found in api/helpers/auth.js - About 1 hr to fix

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

              export function getProperties(request, response) {
                // key was request._key before
                // key is type of data user is querying
                // ex: mobility, population...
                let key = request.swagger.apiPath.split('/')[2]
              Severity: Minor
              Found in api/controllers/general.js - About 1 hr to fix

                Function buildWhere has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  buildWhere(params) {
                    let group_by = null;
                    if (params.group_by) {
                      group_by = params.group_by;
                      delete params.group_by
                Severity: Minor
                Found in api/helpers/postgres.js - About 1 hr 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 value_map has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    let value_map = shapefile.reduce((ary, element) => {
                      let tempList = Object.keys(element).filter(key => {
                        return (key.startsWith('id_'))
                      }).map(key => {
                        return element[key]
                Severity: Minor
                Found in api/helpers/general.js - About 1 hr to fix

                  Function countries_with_this_kind_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                  export const countries_with_this_kind_data = (kind, source, country) => {
                    return new Promise((resolve, reject) => {
                      // Get country name for each shapefile
                      getShapeFiles(kind, source)
                        .then(shapefileSet => {
                  Severity: Minor
                  Found in api/helpers/general.js - About 55 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

                  Severity
                  Category
                  Status
                  Source
                  Language