resource-watch/dataset

View on GitHub

Showing 122 of 122 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    static async getUsersWithRole(role, apiKey) {
        const body = await RWAPIMicroservice.requestToMicroservice({
            uri: `/auth/user/ids/${role}`,
            method: 'GET',
            json: true,
Severity: Major
Found in src/services/user.service.js and 1 other location - About 2 hrs to fix
src/services/user.service.js on lines 34..46

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 91.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    static async getUserById(userId, apiKey) {
        const body = await RWAPIMicroservice.requestToMicroservice({
            uri: `/auth/user/${userId}`,
            method: 'GET',
            json: true,
Severity: Major
Found in src/services/user.service.js and 1 other location - About 2 hrs to fix
src/services/user.service.js on lines 20..32

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 91.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        try {
            logger.debug('Updating widgets');
            await RWAPIMicroservice.requestToMicroservice({
                uri: `/v1/widget/change-environment/${datasetId}/${env}`,
                method: 'PATCH',
Severity: Major
Found in src/services/dataset.service.js and 1 other location - About 2 hrs to fix
src/services/dataset.service.js on lines 356..368

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 90.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

        try {
            logger.debug('Updating layers');
            await RWAPIMicroservice.requestToMicroservice({
                uri: `/v1/layer/change-environment/${datasetId}/${env}`,
                method: 'PATCH',
Severity: Major
Found in src/services/dataset.service.js and 1 other location - About 2 hrs to fix
src/services/dataset.service.js on lines 343..355

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 90.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        const serializeObjToQuery = (obj) => Object.keys(obj).reduce((a, k) => {
            a.push(`${k}=${encodeURIComponent(obj[k])}`);
            return a;
        }, []).join('&');
        Severity: Major
        Found in src/services/relationships.service.js and 1 other location - About 2 hrs to fix
        src/routes/api/v1/dataset.router.js on lines 29..32

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 79.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Identical blocks of code found in 2 locations. Consider refactoring.
        Open

        const serializeObjToQuery = (obj) => Object.keys(obj).reduce((a, k) => {
            a.push(`${k}=${encodeURIComponent(obj[k])}`);
            return a;
        }, []).join('&');
        Severity: Major
        Found in src/routes/api/v1/dataset.router.js and 1 other location - About 2 hrs to fix
        src/services/relationships.service.js on lines 7..10

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 79.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        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

          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
                        Severity
                        Category
                        Status
                        Source
                        Language