resource-watch/dataset

View on GitHub

Showing 60 of 122 total issues

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 validateCreation has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async validateCreation(koaObj) {
            logger.info('Validating Dataset Creation');
            koaObj.checkBody('name').notEmpty().check((name) => DatasetValidator.notEmptyString(name), 'can not be empty');
            koaObj.checkBody('type').optional().check((type) => DatasetValidator.isString(type), 'must be a string');
            koaObj.checkBody('subtitle').optional().check((subtitle) => DatasetValidator.isString(subtitle), 'must be a string');
    Severity: Minor
    Found in src/validators/dataset.validator.js - About 1 hr to fix

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

      const authorizationMiddleware = async (ctx, next) => {
          logger.info(`[DatasetRouter] Checking authorization`);
          // Get user from query (delete) or body (post-patch)
          const newDatasetCreation = ctx.request.path === '/dataset' && ctx.request.method === 'POST';
          const uploadDataset = ctx.request.path.indexOf('upload') >= 0 && ctx.request.method === 'POST';
      Severity: Minor
      Found in src/routes/api/v1/dataset.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 serializeElement has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static serializeElement(el) {
              return {
                  id: el._id,
                  type: 'dataset',
                  attributes: {
      Severity: Minor
      Found in src/serializers/dataset.serializer.js - About 1 hr to fix

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

            static async getAll(apiKey, query = {}, isAdmin = false) {
                logger.debug(`[DatasetService]: Getting all datasets`);
                const sort = query.sort || '';
                const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
                const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
        Severity: Minor
        Found in src/services/dataset.service.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 src/loader.js - About 1 hr to fix

            Function notifyAdapter has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async notifyAdapter(ctx, dataset) {
                    const { connectorType, provider } = dataset;
                    const clonedDataset = { ...dataset.toObject() };
                    clonedDataset.id = dataset._id;
                    clonedDataset.connector_url = dataset.connectorUrl;
            Severity: Minor
            Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

              Function validateUpdate has 39 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  static async validateUpdate(koaObj) {
                      logger.info('Validating Dataset Update');
                      koaObj.checkBody('name').optional().check((name) => DatasetValidator.notEmptyString(name), 'can not be empty');
                      koaObj.checkBody('type').optional().check((type) => DatasetValidator.isString(type), 'must be a string');
                      koaObj.checkBody('subtitle').optional().check((subtitle) => DatasetValidator.isString(subtitle), 'must be a string');
              Severity: Minor
              Found in src/validators/dataset.validator.js - About 1 hr to fix

                Function clone has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async clone(id, dataset, user, apiKey, fullCloning = false) {
                        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: Minor
                Found in src/services/dataset.service.js - About 1 hr to fix

                  Function authorizationMiddleware has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const authorizationMiddleware = async (ctx, next) => {
                      logger.info(`[DatasetRouter] Checking authorization`);
                      // Get user from query (delete) or body (post-patch)
                      const newDatasetCreation = ctx.request.path === '/dataset' && ctx.request.method === 'POST';
                      const uploadDataset = ctx.request.path.indexOf('upload') >= 0 && ctx.request.method === 'POST';
                  Severity: Minor
                  Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

                    Function checkSecureDeleteResources has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        static async checkSecureDeleteResources(id, apiKey) {
                            logger.info('Checking if it is safe to delete the associated resources (layer, widget) of the dataset');
                            try {
                                const layers = await RWAPIMicroservice.requestToMicroservice({
                                    uri: `/v1/dataset/${id}/layer?protected=true`,
                    Severity: Minor
                    Found in src/services/dataset.service.js - About 1 hr to fix

                      Function serialize has 34 lines of code (exceeds 25 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

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

                            static async update(ctx) {
                                const id = ctx.params.dataset;
                                logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
                                try {
                                    const user = DatasetRouter.getUser(ctx);
                        Severity: Minor
                        Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

                          Consider simplifying this complex logical expression.
                          Open

                                      if (
                                          search
                                          || serializeObjToQuery(query).indexOf('concepts[0][0]') >= 0
                                          || sort.indexOf('most-favorited') >= 0
                                          || sort.indexOf('most-viewed') >= 0
                          Severity: Critical
                          Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

                            Function getRelationships has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                static async getRelationships(datasets, includes, apiKey, query = '', isAdmin = false) {
                                    logger.info(`Getting relationships of datasets`, isAdmin);
                                    datasets.unshift({});
                                    const map = datasets.reduce((acc, val) => {
                                        acc[val._id] = val;
                            Severity: Minor
                            Found in src/services/relationships.service.js - About 1 hr to fix

                              Function notifyAdapterCreate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  static async notifyAdapterCreate(ctx, dataset) {
                                      const { connectorType, provider } = dataset;
                                      const clonedDataset = { ...dataset.toObject() };
                              
                                      clonedDataset.id = dataset._id;
                              Severity: Minor
                              Found in src/routes/api/v1/dataset.router.js - About 1 hr to fix

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

                                    const loadAPI = (app, path, pathApi) => {
                                        const routesFiles = fs.readdirSync(path);
                                        let existIndexRouter = false;
                                        routesFiles.forEach((file) => {
                                            const newPath = path ? (`${path}/${file}`) : file;
                                Severity: Minor
                                Found in src/loader.js - About 1 hr to fix

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

                                      static async update(ctx) {
                                          const id = ctx.params.dataset;
                                          logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
                                          try {
                                              const user = DatasetRouter.getUser(ctx);
                                  Severity: Minor
                                  Found in src/routes/api/v1/dataset.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 getFields has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      static async getFields(filePath, provider) {
                                          logger.debug('Obtaining fields');
                                          let fields = null;
                                          try {
                                              switch (provider) {
                                  Severity: Minor
                                  Found in src/services/fileDataService.service.js - About 1 hr to fix

                                    Function updateEnv has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        static async updateEnv(datasetId, env, apiKey) {
                                            logger.debug('Updating env of all resources of dataset', datasetId, 'with env ', env);
                                            try {
                                                logger.debug('Updating widgets');
                                                await RWAPIMicroservice.requestToMicroservice({
                                    Severity: Minor
                                    Found in src/services/dataset.service.js - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language