resource-watch/vocabulary-tag

View on GitHub

Showing 111 of 111 total issues

Function updateTagsFromRelationship has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async updateTagsFromRelationship(pVocabulary, dataset, pResource, body, apiKey) {
        logger.debug(`Checking entities`);
        const vocabulary = await VocabularyService.getById(pVocabulary);
        if (!vocabulary) {
            logger.debug(`This Vocabulary doesn't exist`);
Severity: Minor
Found in app/src/services/relationship.service.js - About 2 hrs to fix

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

        static getFilteredQuery(query, user) {
            const application = query.application || query.app || 'rw';
    
            const filters = {
                ownerId: query.ownerId || user.id,
    Severity: Minor
    Found in app/src/services/collection.service.js - About 1 hr to fix

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

                      el.vocabularies.forEach((vocabulary) => {
                          result.data.push({
                              id: vocabulary.id,
                              type: 'vocabulary',
                              attributes: {
      Severity: Major
      Found in app/src/serializers/resource.serializer.js and 1 other location - About 1 hr to fix
      app/src/serializers/vocabulary.serializer.js on lines 14..24

      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 71.

      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

                  data.forEach((el) => {
                      result.data.push({
                          id: el.id,
                          type: 'vocabulary',
                          attributes: {
      Severity: Major
      Found in app/src/serializers/vocabulary.serializer.js and 1 other location - About 1 hr to fix
      app/src/serializers/resource.serializer.js on lines 15..25

      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 71.

      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

                  } else if (Array.isArray(data)) {
                      result.data = data.map((el) => CollectionSerializer.serializeElement(el));
                  } else {
                      result.data = CollectionSerializer.serializeElement(data);
                  }
      Severity: Major
      Found in app/src/serializers/collection.serializer.js and 1 other location - About 1 hr to fix
      app/src/serializers/favourite.serializer.js on lines 21..25

      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 69.

      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

                  if (Array.isArray(data)) {
                      result.data = data.map((el) => FavouriteSerializer.serializeElement(el));
                  } else {
                      result.data = FavouriteSerializer.serializeElement(data);
                  }
      Severity: Major
      Found in app/src/serializers/favourite.serializer.js and 1 other location - About 1 hr to fix
      app/src/serializers/collection.serializer.js on lines 36..40

      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 69.

      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 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

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

                            const datasetResources = await RWAPIMicroservice.requestToMicroservice({
                                uri: `/v1/dataset?ids=${datasets.join(',')}`,
                                method: 'GET',
                                headers: {
                                    'x-api-key': ctx.request.headers['x-api-key']
        Severity: Major
        Found in app/src/routes/api/v1/favourite.router.js and 1 other location - About 1 hr to fix
        app/src/routes/api/v1/favourite.router.js on lines 70..76

        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 68.

        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

                            const widgetResources = await RWAPIMicroservice.requestToMicroservice({
                                uri: `/v1/widget?ids=${widgets.join(',')}`,
                                method: 'GET',
                                headers: {
                                    'x-api-key': ctx.request.headers['x-api-key']
        Severity: Major
        Found in app/src/routes/api/v1/favourite.router.js and 1 other location - About 1 hr to fix
        app/src/routes/api/v1/favourite.router.js on lines 49..55

        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 68.

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

            static async updateRelationships(ctx) {
                const { dataset } = ctx.params;
                const resource = VocabularyRouter.getResource(ctx.params);
                const { body } = ctx.request;
                logger.info(`Deleting All Vocabularies of resource: ${resource.type} - ${resource.id}`);
        Severity: Minor
        Found in app/src/routes/api/v1/vocabulary.router.js - About 1 hr to fix

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

              static serialize(data, link = null) {
                  const result = {};
                  if (data) {
                      if (data.docs) {
                          while (data.docs.indexOf(undefined) >= 0) {
          Severity: Minor
          Found in app/src/serializers/collection.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

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

              static async updateTagsFromRelationship(pVocabulary, dataset, pResource, body, apiKey) {
                  logger.debug(`Checking entities`);
                  const vocabulary = await VocabularyService.getById(pVocabulary);
                  if (!vocabulary) {
                      logger.debug(`This Vocabulary doesn't exist`);
          Severity: Minor
          Found in app/src/services/relationship.service.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 create has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static async create(pVocabulary, dataset, pResource, body, apiKey) {
                  logger.debug(`Checking entities`);
                  let vocabulary = await VocabularyService.getById(pVocabulary);
                  if (!vocabulary || vocabulary.length === 0) {
                      logger.debug(`This Vocabulary doesn't exist, let's create it`);
          Severity: Minor
          Found in app/src/services/relationship.service.js - About 1 hr to fix

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

                static async validate(ctx) {
                    logger.info('Validating Collection Creation');
            
                    ctx.checkBody('name').notEmpty();
                    ctx.checkBody('application').optional().toLow();
            Severity: Minor
            Found in app/src/validators/collection.validator.js - About 1 hr to fix

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

                      if (ctx.errors) {
                          logger.debug('errors ', ctx.errors);
                          ctx.body = ErrorSerializer.serializeValidationBodyErrors(ctx.errors);
                          ctx.status = 400;
                          return;
              Severity: Major
              Found in app/src/validators/collection.validator.js and 1 other location - About 1 hr to fix
              app/src/validators/favourite.validator.js on lines 13..18

              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 64.

              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

                      if (ctx.errors) {
                          logger.debug('errors ', ctx.errors);
                          ctx.body = ErrorSerializer.serializeValidationBodyErrors(ctx.errors);
                          ctx.status = 400;
                          return;
              Severity: Major
              Found in app/src/validators/favourite.validator.js and 1 other location - About 1 hr to fix
              app/src/validators/collection.validator.js on lines 28..33

              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 64.

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

                  static async get(dataset, resource, vocabulary) {
                      const query = {
                          dataset,
                          id: resource.id,
                          type: resource.type,
              Severity: Minor
              Found in app/src/services/resource.service.js - About 1 hr to fix

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

                        try {
                            await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
                        } catch (error) {
                            ctx.throw(404, `User ${userIdToDelete} does not exist`);
                        }
                Severity: Major
                Found in app/src/routes/api/v1/favourite.router.js and 1 other location - About 1 hr to fix
                app/src/routes/api/v1/collection.router.js on lines 144..148

                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 61.

                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

                            await RWAPIMicroservice.requestToMicroservice({
                                uri: `/v1/graph/favourite/${favourite.resourceType}/${favourite.resourceId}/${favourite._id}`,
                                method: 'DELETE',
                                headers: {
                                    'x-api-key': apiKey
                Severity: Major
                Found in app/src/services/graph.service.js and 1 other location - About 1 hr to fix
                app/src/services/graph.service.js on lines 8..14

                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 61.

                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

                        try {
                            await UserService.getUserById(userIdToDelete, ctx.request.headers['x-api-key']);
                        } catch (error) {
                            ctx.throw(404, `User ${userIdToDelete} does not exist`);
                        }
                Severity: Major
                Found in app/src/routes/api/v1/collection.router.js and 1 other location - About 1 hr to fix
                app/src/routes/api/v1/favourite.router.js on lines 181..185

                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 61.

                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

                Severity
                Category
                Status
                Source
                Language