gfw-api/gfw-subscription-api

View on GitHub

Showing 129 of 129 total issues

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

async function init() {
    return new Promise((resolve, reject) => {
        async function onDbReady(mongoConnectionError) {
            if (mongoConnectionError) {
                if (retries >= 0) {
Severity: Major
Found in app/src/app.js - About 3 hrs to fix

    File datasetService.js has 311 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* eslint-disable no-continue */
    const Subscription = require('models/subscription');
    const ctRegisterMicroservice = require('ct-register-microservice-node');
    const MailService = require('services/mailService');
    const JSONAPIDeserializer = require('jsonapi-serializer').Deserializer;
    Severity: Minor
    Found in app/src/services/datasetService.js - About 3 hrs to fix

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

          static pathFor(subscription, layerSlug) {
              const params = subscription.params || {};
      
              if (layerSlug === 'story') {
                  if (params.iso && params.iso.country) {
      Severity: Minor
      Found in app/src/services/analysisClassifier.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

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

              async function onDbReady(mongoConnectionError) {
                  if (mongoConnectionError) {
                      if (retries >= 0) {
                          retries--;
                          logger.error(`Failed to connect to MongoDB uri ${mongoUri}, retrying...`);
      Severity: Major
      Found in app/src/app.js - About 3 hrs to fix

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

            static getURLInPeriodForWDPA(startDate, endDate, params = {}) {
                const { wdpaid } = params;
                let sql = `SELECT * FROM data WHERE alert__date > '${startDate}' AND alert__date <= '${endDate}' `;
                sql += `AND wdpa_protected_area__id = '${wdpaid}'`;
                sql += ' ORDER BY alert__date';
        Severity: Major
        Found in app/src/services/viirsAlertsService.js and 1 other location - About 3 hrs to fix
        app/src/services/gladAlertsService.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 100.

        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 getURLInPeriodForWDPA(startDate, endDate, params = {}) {
                const { wdpaid } = params;
                let sql = `SELECT * FROM data WHERE alert__date > '${startDate}' AND alert__date <= '${endDate}' `;
                sql += `AND wdpa_protected_area__id = '${wdpaid}'`;
                sql += ' ORDER BY alert__date';
        Severity: Major
        Found in app/src/services/gladAlertsService.js and 1 other location - About 3 hrs to fix
        app/src/services/viirsAlertsService.js on lines 48..54

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

        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

            'terrai-alerts': {
                layerSlug: 'terrai-alerts',
                alert_name: 'Brazil Alerts',
                selected_area: 'ISO Code: BRA',
                unsubscribe_url: 'http://www.globalforestwatch.org/unsubscribe_url',
        Severity: Major
        Found in app/src/services/mockService.js and 1 other location - About 3 hrs to fix
        app/src/services/mockService.js on lines 111..131

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

        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

            'glad-alerts': {
                layerSlug: 'glad-alerts',
                alert_name: 'Brazil Alerts',
                selected_area: 'ISO Code: BRA',
                unsubscribe_url: 'http://www.globalforestwatch.org/unsubscribe_url',
        Severity: Major
        Found in app/src/services/mockService.js and 1 other location - About 3 hrs to fix
        app/src/services/mockService.js on lines 90..110

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

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

            static async infoGroupSubscriptions(startDate, endDate, application) {
                logger.debug(`Obtaining group subscriptions with startDate ${startDate}, endDate ${endDate} and application ${application}`);
                const filter = {
                    createdAt: { $gte: startDate, $lt: endDate },
                    datasets: { $ne: [] },
        Severity: Major
        Found in app/src/services/statisticsService.js - About 3 hrs to fix

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

              static async getAnalysisInPeriodForSubscription(startDate, endDate, params) {
                  logger.info('Entering GLAD analysis endpoint with params', startDate, endDate, params);
                  const uri = await GLADAlertsService.getURLInPeriodForSubscription(startDate, endDate, params);
                  const response = await ctRegisterMicroservice.requestToMicroservice({ uri, method: 'GET', json: true });
                  return response.data;
          Severity: Major
          Found in app/src/services/gladAlertsService.js and 1 other location - About 2 hrs to fix
          app/src/services/viirsAlertsService.js on lines 103..108

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

          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 getAnalysisInPeriodForSubscription(startDate, endDate, params) {
                  logger.info('Entering VIIRS analysis endpoint with params', startDate, endDate, params);
                  const uri = await ViirsAlertsService.getURLInPeriodForSubscription(startDate, endDate, params);
                  const response = await ctRegisterMicroservice.requestToMicroservice({ uri, method: 'GET', json: true });
                  return response.data;
          Severity: Major
          Found in app/src/services/viirsAlertsService.js and 1 other location - About 2 hrs to fix
          app/src/services/gladAlertsService.js on lines 104..109

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

          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

              'viirs-active-fires': {
                  layerSlug: 'viirs-active-fires',
                  alert_name: 'Brazil Alerts',
                  selected_area: 'ISO Code: BRA',
                  unsubscribe_url: 'http://www.globalforestwatch.org/unsubscribe_url',
          Severity: Major
          Found in app/src/services/mockService.js and 1 other location - About 2 hrs to fix
          app/src/services/mockService.js on lines 61..78

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

          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

              'forma-alerts': {
                  layerSlug: 'forma-alerts',
                  alert_name: 'Brazil Alerts',
                  selected_area: 'ISO Code: BRA',
                  unsubscribe_url: 'http://www.globalforestwatch.org/unsubscribe_url',
          Severity: Major
          Found in app/src/services/mockService.js and 1 other location - About 2 hrs to fix
          app/src/services/mockService.js on lines 2..19

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

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

          module.exports = (() => {
              const loadAPI = (app, path = routersPath, pathApi) => {
                  const routesFiles = fs.readdirSync(path);
                  let existIndexRouter = false;
                  routesFiles.forEach((file) => {
          Severity: Major
          Found in app/src/loader.js - About 2 hrs to fix

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

            const transformAndSaveData = async (data) => {
                logger.info('Saving data');
                if (data) {
                    for (let i = 0, { length } = data; i < length; i++) {
                        if (data[i].confirmed) {
            Severity: Major
            Found in app/src/migrate/migrate.js - About 2 hrs to fix

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

                  static async getAnalysisSamePeriodLastYearForSubscription(startDate, endDate, params) {
                      const lastYearStartDate = moment(startDate).subtract('1', 'y');
                      const lastYearEndDate = moment(endDate).subtract('1', 'y');
                      return ViirsAlertsService.getAnalysisInPeriodForSubscription(
                          lastYearStartDate.format('YYYY-MM-DD'),
              Severity: Major
              Found in app/src/services/viirsAlertsService.js and 1 other location - About 2 hrs to fix
              app/src/services/gladAlertsService.js on lines 119..127

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

              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 getAnalysisSamePeriodLastYearForSubscription(startDate, endDate, params) {
                      const lastYearStartDate = moment(startDate).subtract('1', 'y');
                      const lastYearEndDate = moment(endDate).subtract('1', 'y');
                      return GLADAlertsService.getAnalysisInPeriodForSubscription(
                          lastYearStartDate.format('YYYY-MM-DD'),
              Severity: Major
              Found in app/src/services/gladAlertsService.js and 1 other location - About 2 hrs to fix
              app/src/services/viirsAlertsService.js on lines 118..126

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

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

                  static async transform(results, layer, subscription, begin, end) {
                      EmailHelpersService.updateMonthTranslations();
                      moment.locale(subscription.language || 'en');
              
                      try {
              Severity: Major
              Found in app/src/presenters/monthlySummaryPresenter.js - About 2 hrs to fix

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

                    static async getGeostoreFromISORegionCode(countryCode, regionCode) {
                        const uri = `/v2/geostore/admin/${countryCode}/${regionCode}`;
                        const response = await ctRegisterMicroservice.requestToMicroservice({
                            uri,
                            method: 'GET',
                Severity: Major
                Found in app/src/services/geostoreService.js and 1 other location - About 2 hrs to fix
                app/src/services/geostoreService.js on lines 79..88

                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

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

                    static async getGeostoreFromUseId(use, useId) {
                        const uri = `/v2/geostore/use/${use}/${useId}`;
                        const response = await ctRegisterMicroservice.requestToMicroservice({
                            uri,
                            method: 'GET',
                Severity: Major
                Found in app/src/services/geostoreService.js and 1 other location - About 2 hrs to fix
                app/src/services/geostoreService.js on lines 46..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 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

                Severity
                Category
                Status
                Source
                Language