gfw-api/gfw-forms-api

View on GitHub

Showing 32 of 63 total issues

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

const Router = require('koa-router');
const logger = require('logger');
const ReportsSerializer = require('serializers/reportsSerializer');
const ReportsModel = require('models/reportsModel');
const ReportsValidator = require('validators/reportsValidator');
Severity: Minor
Found in app/src/routes/api/v1/reports.router.js - About 5 hrs to fix

    Function save has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

        static* save() {
            logger.info('Saving answer');
            logger.debug(this.request.body);
    
            const { fields } = this.request.body;
    Severity: Minor
    Found in app/src/routes/api/v1/answers.router.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 save has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

        static* save() {
            logger.info('Saving questionnaire');
            logger.debug(this.request.body);
    
            const answer = {
    Severity: Minor
    Found in app/src/routes/api/v1/questionnaireAnswer.router.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 create has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        static* create(next) {
            const request = this.request.body;
            logger.debug('Validating body for create template');
            this.checkBody('name').notEmpty();
            this.checkBody('questions').notEmpty();
    Severity: Minor
    Found in app/src/validators/reportsValidator.js - About 3 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 downloadAnswers has 82 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static* downloadAnswers() {
            logger.info(`Downloading answers for report ${this.params.id}`);
            this.set('Content-disposition', `attachment; filename=${this.params.id}.csv`);
            this.set('Content-type', 'text/csv');
            this.body = passThrough();
    Severity: Major
    Found in app/src/routes/api/v1/reports.router.js - About 3 hrs to fix

      Function init has 81 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 3 hrs to fix

        Function exports has 71 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 2 hrs to fix

          Function onDbReady has 71 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async function onDbReady(err) {
                      if (err) {
                          if (retries >= 0) {
                              // eslint-disable-next-line no-plusplus
                              retries--;
          Severity: Major
          Found in app/src/app.js - About 2 hrs to fix

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

                static* save() {
                    logger.info('Saving answer');
                    logger.debug(this.request.body);
            
                    const { fields } = this.request.body;
            Severity: Major
            Found in app/src/routes/api/v1/answers.router.js - About 2 hrs to fix

              Function patch has 70 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static* patch() {
                      logger.info(`Updating template with id ${this.params.id}...`);
              
                      const reportFilter = {
                          $and: [
              Severity: Major
              Found in app/src/routes/api/v1/reports.router.js - About 2 hrs to fix

                Function create has 58 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static* create(next) {
                        const request = this.request.body;
                        logger.debug('Validating body for create template');
                        this.checkBody('name').notEmpty();
                        this.checkBody('questions').notEmpty();
                Severity: Major
                Found in app/src/validators/reportsValidator.js - About 2 hrs to fix

                  Function patch has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
                  Open

                      static* patch() {
                          logger.info(`Updating template with id ${this.params.id}...`);
                  
                          const reportFilter = {
                              $and: [
                  Severity: Minor
                  Found in app/src/routes/api/v1/reports.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 delete has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      static* delete() {
                          const { role } = this.state.loggedUser;
                          const aoi = this.state.query && this.state.query.aoi !== null ? this.state.query.aoi.split(',') : null;
                          logger.info(`Checking report for answers...`);
                          const answers = yield AnswersModel.count({ report: new ObjectId(this.params.id) });
                  Severity: Minor
                  Found in app/src/routes/api/v1/reports.router.js - About 2 hrs to fix

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

                        static* save() {
                            logger.info('Saving questionnaire');
                            logger.debug(this.request.body);
                    
                            const answer = {
                    Severity: Minor
                    Found in app/src/routes/api/v1/questionnaireAnswer.router.js - About 1 hr to fix

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

                          static* getAllAnswers({
                              reportId, template, loggedUser, team, query
                          }) {
                              let filter = {};
                              let currentManager = false;
                      Severity: Minor
                      Found in app/src/services/answersService.js - About 1 hr to fix

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

                            static* downloadAnswers() {
                                logger.info(`Download answers of questionnaire ${this.params.id}`);
                                this.set('Content-disposition', `attachment; filename=${this.params.id}.csv`);
                                this.set('Content-type', 'text/csv');
                                this.body = passThrough();
                        Severity: Minor
                        Found in app/src/routes/api/v1/questionnaire.router.js - About 1 hr to fix

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

                          module.exports = (() => {
                          
                              const loadAPI = (app, path, pathApi) => {
                                  const routesFiles = fs.readdirSync(path);
                                  let existIndexRouter = false;
                          Severity: Minor
                          Found in app/src/loader.js - About 1 hr to fix

                            Function downloadAnswers has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                            Open

                                static* downloadAnswers() {
                                    logger.info(`Download answers of questionnaire ${this.params.id}`);
                                    this.set('Content-disposition', `attachment; filename=${this.params.id}.csv`);
                                    this.set('Content-type', 'text/csv');
                                    this.body = passThrough();
                            Severity: Minor
                            Found in app/src/routes/api/v1/questionnaire.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 save has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                static* save() {
                                    logger.info('Saving reports', this.request.body);
                                    const request = this.request.body;
                            
                                    if (request.public && this.state.loggedUser.role !== 'ADMIN') {
                            Severity: Minor
                            Found in app/src/routes/api/v1/reports.router.js - About 1 hr to fix

                              Function downloadAnswers has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  static* downloadAnswers() {
                                      logger.info(`Downloading answers for report ${this.params.id}`);
                                      this.set('Content-disposition', `attachment; filename=${this.params.id}.csv`);
                                      this.set('Content-type', 'text/csv');
                                      this.body = passThrough();
                              Severity: Minor
                              Found in app/src/routes/api/v1/reports.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

                              Severity
                              Category
                              Status
                              Source
                              Language