resource-watch/dataset

View on GitHub

Showing 59 of 116 total issues

File dataset.service.js has 684 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const { URL } = require('url');
const { default: logger } = require('logger');
const Dataset = require('models/dataset.model');
const RelationshipsService = require('services/relationships.service');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
Severity: Major
Found in src/services/dataset.service.js - About 1 day to fix

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

    Severity: Major
    Found in src/routes/api/v1/dataset.router.js - About 1 day to fix

      Function getAll has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
      Open

      Severity: Minor
      Found in src/routes/api/v1/dataset.router.js - About 7 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 41 (exceeds 5 allowed). Consider refactoring.
      Open

          static async update(id, dataset, user) {
              logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
              logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
      
              const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
      Severity: Minor
      Found in src/services/dataset.service.js - About 6 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 getAll has 116 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      Severity: Major
      Found in src/routes/api/v1/dataset.router.js - About 4 hrs to fix

        Function update has 108 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async update(id, dataset, user) {
                logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
                logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
        
                const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
        Severity: Major
        Found in src/services/dataset.service.js - About 4 hrs to fix

          Function getResources has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
          Open

              static async getResources(ids, includes, query = '', users = [], isAdmin = false) {
                  logger.info(`Getting resources of ids: ${ids}`);
                  delete query.ids;
                  delete query.usersRole;
                  let resources = includes.map(async (include) => {
          Severity: Minor
          Found in src/services/relationships.service.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

          File relationships.service.js has 313 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          const { default: logger } = require('logger');
          const { RWAPIMicroservice } = require('rw-api-microservice-node');
          const { INCLUDES } = require('app.constants');
          const { compact, uniq, startsWith, pickBy } = require('lodash');
          const InvalidRequest = require('errors/invalidRequest.error');
          Severity: Minor
          Found in src/services/relationships.service.js - About 3 hrs to fix

            Function getResources has 86 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async getResources(ids, includes, query = '', users = [], isAdmin = false) {
                    logger.info(`Getting resources of ids: ${ids}`);
                    delete query.ids;
                    delete query.usersRole;
                    let resources = includes.map(async (include) => {
            Severity: Major
            Found in src/services/relationships.service.js - About 3 hrs to fix

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

                  static async create(dataset, user) {
                      logger.debug(`[DatasetService]: Getting dataset with name:  ${dataset.name}`);
                      logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
                      const tempSlug = await DatasetService.getSlug(dataset.name);
                      // Check if raw dataset
              Severity: Major
              Found in src/services/dataset.service.js - About 3 hrs to fix

                Function create has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
                Open

                    static async create(dataset, user) {
                        logger.debug(`[DatasetService]: Getting dataset with name:  ${dataset.name}`);
                        logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
                        const tempSlug = await DatasetService.getSlug(dataset.name);
                        // Check if raw dataset
                Severity: Minor
                Found in src/services/dataset.service.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

                DatasetService has 27 functions (exceeds 20 allowed). Consider refactoring.
                Open

                class DatasetService {
                
                    // eslint-disable-next-line consistent-return
                    static async getSlug(name) {
                        const valid = false;
                Severity: Minor
                Found in src/services/dataset.service.js - About 3 hrs to fix

                  Function getFilteredQuery has 77 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      static getFilteredQuery(query, ids = []) {
                          const { collection, favourite } = query;
                          if (!query.application && query.app) {
                              query.application = query.app;
                              if (favourite) {
                  Severity: Major
                  Found in src/services/dataset.service.js - About 3 hrs to fix

                    File dataset.validator.js has 286 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    const { default: logger } = require('logger');
                    const DatasetNotValid = require('errors/datasetNotValid.error');
                    const { CONNECTOR_TYPES } = require('app.constants');
                    const { RASDAMAN_TYPES } = require('app.constants');
                    const { URL } = require('url');
                    Severity: Minor
                    Found in src/validators/dataset.validator.js - About 2 hrs to fix

                      Function init has 63 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

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

                        Function checkConnectorUrl has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                        Open

                            static checkConnectorUrl(connectorUrl, koaObj) {
                                let validation = false;
                                const {
                                    connectorType, provider, data, tableName, sources
                                } = koaObj.request.body;
                        Severity: Minor
                        Found in src/validators/dataset.validator.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 59 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            static async delete(id, user) {
                                logger.debug(`[DatasetService]: Getting dataset with id:  ${id}`);
                                logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
                                const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
                                    slug: id
                        Severity: Major
                        Found in src/services/dataset.service.js - About 2 hrs to fix

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

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

                            Consider simplifying this complex logical expression.
                            Open

                                    } else if (connectorType === 'rest' && (provider === 'gee' || provider === 'bigquery' || provider === 'nexgddp' || provider === 'loca')) {
                                        // is it tableName valid?
                                        if (DatasetValidator.notEmptyString(tableName)) {
                                            validation = true;
                                            // if tableName not provided
                            Severity: Critical
                            Found in src/validators/dataset.validator.js - About 2 hrs to fix

                              Function serialize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  static serialize(data, link = null) {
                                      const result = {};
                                      if (data && Array.isArray(data) && data.length === 0) {
                                          result.data = [];
                                          return result;
                              Severity: Minor
                              Found in src/serializers/dataset.serializer.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