resource-watch/dataset

View on GitHub

Showing 60 of 122 total issues

File dataset.service.js has 724 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 575 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const Router = require('koa-router');
    const koaMulter = require('koa-multer');
    const { default: logger } = require('logger');
    const xor = require('lodash/xor');
    const DatasetService = require('services/dataset.service');
    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

          static async getAll(ctx) {
              logger.info(`[DatasetRouter] Getting all datasets`);
              const user = DatasetRouter.getUser(ctx);
              const { query } = ctx;
              const { search } = query;
      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, apiKey) {
              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 117 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async getAll(ctx) {
              logger.info(`[DatasetRouter] Getting all datasets`);
              const user = DatasetRouter.getUser(ctx);
              const { query } = ctx;
              const { search } = query;
      Severity: Major
      Found in src/routes/api/v1/dataset.router.js - About 4 hrs to fix

        File relationships.service.js has 350 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 4 hrs to fix

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

              static async update(id, dataset, user, apiKey) {
                  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, apiKey, 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

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

                static async getResources(ids, includes, apiKey, 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 87 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async create(dataset, user, apiKey) {
                      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, apiKey) {
                        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 28 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 67 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 onDbReady has 61 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

                          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(dataset, user, apiKey, applicationBasedDelete = true) {
                                  logger.debug(`[DatasetService]: Getting dataset with id: ${dataset.id}`);
                                  logger.info(`[DBACCESS-FIND]: dataset.id: ${dataset.id}`);
                                  const id = dataset.id;
                                  if (!dataset) {
                          Severity: Major
                          Found in src/services/dataset.service.js - About 2 hrs to fix

                            Function serialize has a Cognitive Complexity of 17 (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 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 resources has 50 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                    let resources = includes.map(async (include) => {
                                        const obj = {};
                                        if (INCLUDES.indexOf(include) >= 0) {
                                            let uri = '/v1';
                                            let payload = {
                            Severity: Minor
                            Found in src/services/relationships.service.js - About 2 hrs to fix
                              Severity
                              Category
                              Status
                              Source
                              Language