gfw-api/gfw-area

View on GitHub

Showing 44 of 126 total issues

File area.router.js has 692 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const Router = require('koa-router');
const logger = require('logger');
const config = require('config');
const moment = require('moment');
const AreaSerializerV2 = require('serializers/area.serializerV2');
Severity: Major
Found in app/src/routes/api/v2/area.router.js - About 1 day to fix

    Function update has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring.
    Open

        static async update(ctx) {
            let previousArea = await AreaModel.findById(ctx.params.id);
            let area = await AreaModel.findById(ctx.params.id);
            if (!area) {
                // Try to find subscription with same ID
    Severity: Minor
    Found in app/src/routes/api/v2/area.router.js - About 1 day 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 save has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

        static async save(ctx) {
            logger.info('Saving v2 area', ctx.request.body);
            const userId = ctx.state.loggedUser.id;
            let isSaved = false;
    
    
    Severity: Minor
    Found in app/src/routes/api/v2/area.router.js - About 1 day 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 update has 132 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async update(ctx) {
            let previousArea = await AreaModel.findById(ctx.params.id);
            let area = await AreaModel.findById(ctx.params.id);
            if (!area) {
                // Try to find subscription with same ID
    Severity: Major
    Found in app/src/routes/api/v2/area.router.js - About 5 hrs to fix

      Function save has 130 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async save(ctx) {
              logger.info('Saving v2 area', ctx.request.body);
              const userId = ctx.state.loggedUser.id;
              let isSaved = false;
      
      
      Severity: Major
      Found in app/src/routes/api/v2/area.router.js - About 5 hrs to fix

        File area.router.js has 319 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        const Router = require('koa-router');
        const logger = require('logger');
        const AreaSerializer = require('serializers/area.serializer');
        const AreaModel = require('models/area.model');
        const AreaValidator = require('validators/area.validator');
        Severity: Minor
        Found in app/src/routes/api/v1/area.router.js - About 3 hrs to fix

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

              static async sync(ctx) {
                  try {
                      // Default interval is the last 2 days
                      let startDate = moment().subtract('2', 'd').hour(0).minute(0);
                      let endDate = moment().hour(0).minute(0);
          Severity: Major
          Found in app/src/routes/api/v2/area.router.js - About 3 hrs to fix

            Function exports has 82 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = (grunt) => {
            
                grunt.file.setBase('..');
                // eslint-disable-next-line import/no-extraneous-dependencies
                require('load-grunt-tasks')(grunt);
            Severity: Major
            Found in app/Gruntfile.js - About 3 hrs to fix

              Function mergeSubscriptionOverArea has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
              Open

                  static async mergeSubscriptionOverArea(area, subscription) {
                      if (area.isNew) {
                          // This is for the serializer to know that it must override the area id with the subscription id
                          area.overrideId = true;
              
              
              Severity: Minor
              Found in app/src/services/subscription.service.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 init has 66 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              async function init() {
                  return new Promise((resolve, reject) => {
                      async function onDbReady(err) {
                          if (err) {
                              if (retries >= 0) {
              Severity: Major
              Found in app/src/app.js - About 2 hrs to fix

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

                    static getRequestBodyForSubscriptionFromArea(area) {
                        const body = {
                            name: area.name,
                            datasets: SubscriptionsService.getDatasetsForSubscription(area),
                            language: area.language,
                Severity: Minor
                Found in app/src/services/subscription.service.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 obtainImages has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                    static async obtainImages(groups, generateImages) {
                        logger.debug('Obtaining images with gropus');
                        const response = [];
                        if (groups) {
                            const keys = Object.keys(groups);
                Severity: Minor
                Found in app/src/services/alerts.service.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 update has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
                Open

                    static async update(ctx) {
                        logger.info(`Updating area with id ${ctx.params.id}`);
                        const area = await AreaModel.findById(ctx.params.id);
                        const { files } = ctx.request;
                        if (ctx.request.body.application || !area.application) {
                Severity: Minor
                Found in app/src/routes/api/v1/area.router.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 onDbReady has 60 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        async function onDbReady(err) {
                            if (err) {
                                if (retries >= 0) {
                                    retries--;
                                    logger.error(`Failed to connect to MongoDB uri ${mongoUri} with error message "${err.message}", retrying...`);
                Severity: Major
                Found in app/src/app.js - About 2 hrs to fix

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

                      static async mergeSubscriptionOverArea(area, subscription) {
                          if (area.isNew) {
                              // This is for the serializer to know that it must override the area id with the subscription id
                              area.overrideId = true;
                  
                  
                  Severity: Major
                  Found in app/src/services/subscription.service.js - About 2 hrs to fix

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

                        static async obtainImages(groups, generateImages) {
                            logger.debug('Obtaining images with gropus');
                            const response = [];
                            if (groups) {
                                const keys = Object.keys(groups);
                    Severity: Major
                    Found in app/src/services/alerts.service.js - About 2 hrs to fix

                      Function delete has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          static async delete(ctx) {
                              logger.info(`Deleting area with id ${ctx.params.id}`);
                              const areaToDelete = await AreaModel.findById(ctx.params.id);
                              if (areaToDelete) {
                                  if (areaToDelete.subscriptionId) {
                      Severity: Minor
                      Found in app/src/routes/api/v2/area.router.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 deleteByUserId has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          static async deleteByUserId(userId, apiKey) {
                              logger.debug(`[AreaService]: Delete areas for user with id:  ${userId}`);
                      
                              const userAreas = await Area.find({ userId: { $eq: userId } }).exec();
                      
                      
                      Severity: Minor
                      Found in app/src/services/area.service.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 deleteByUserId has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                      Open

                          static async deleteByUserId(ctx) {
                              logger.info(`Deleting areas of user with id ${ctx.params.userId}`);
                              const userIdToDelete = ctx.params.userId;
                      
                              try {
                      Severity: Minor
                      Found in app/src/routes/api/v2/area.router.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 update has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          static async update(ctx) {
                              logger.info(`Updating area with id ${ctx.params.id}`);
                              const area = await AreaModel.findById(ctx.params.id);
                              const { files } = ctx.request;
                              if (ctx.request.body.application || !area.application) {
                      Severity: Minor
                      Found in app/src/routes/api/v1/area.router.js - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language