gfw-api/gfw-area

View on GitHub

Showing 126 of 126 total issues

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

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

    Function getRequestBodyForSubscriptionFromArea has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        static getRequestBodyForSubscriptionFromArea(area) {
            const body = {
                name: area.name,
                datasets: SubscriptionsService.getDatasetsForSubscription(area),
                language: area.language,
    Severity: Minor
    Found in app/src/services/subscription.service.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 obtainImages has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        static async obtainImages(groups, generateImages) {
            logger.debug('Obtaining images with gropus');
            const response = [];
            if (groups) {
                const keys = Object.keys(groups);
    Severity: Minor
    Found in app/src/services/alerts.service.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 update has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        static async update(ctx) {
            logger.info(`Updating area with id ${ctx.params.id}`);
            const area = await AreaModel.findById(ctx.params.id);
            const { files } = ctx.request;
            if (ctx.request.body.application || !area.application) {
    Severity: Minor
    Found in app/src/routes/api/v1/area.router.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

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

            if (area.geostore) {
                const areas = await AreaModel.find({
                    status: 'saved',
                    geostore: area.geostore,
                    _id: { $nin: [area.id, area.subscriptionId] }
    Severity: Major
    Found in app/src/services/subscription.service.js and 1 other location - About 2 hrs to fix
    app/src/services/subscription.service.js on lines 128..138

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

    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 (area.geostoreDataApi) {
                const areas = await AreaModel.find({
                    status: 'saved',
                    geostoreDataApi: area.geostoreDataApi,
                    _id: { $nin: [area.id, area.subscriptionId] }
    Severity: Major
    Found in app/src/services/subscription.service.js and 1 other location - About 2 hrs to fix
    app/src/services/subscription.service.js on lines 120..138

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

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

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

      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 app/src/routes/api/v1/area.router.js and 1 other location - About 2 hrs to fix
      app/src/routes/api/v2/area.router.js on lines 89..92

      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 app/src/routes/api/v2/area.router.js and 1 other location - About 2 hrs to fix
      app/src/routes/api/v1/area.router.js on lines 15..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 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

      Area.statics.existsSavedAreaForGeostoreDataApi = async function existsSavedAreaForGeostoreDataApi(geostoreDataApi) {
          const savedAreas = await this.find({ $and: [{ status: 'saved' }, { geostoreDataApi }] });
          return savedAreas && savedAreas.length > 0;
      };
      Severity: Major
      Found in app/src/models/area.modelV2.js and 1 other location - About 2 hrs to fix
      app/src/models/area.modelV2.js on lines 87..90

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

      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

      Area.statics.existsSavedAreaForGeostore = async function existsSavedAreaForGeostore(geostore) {
          const savedAreas = await this.find({ $and: [{ status: 'saved' }, { geostore }] });
          return savedAreas && savedAreas.length > 0;
      };
      Severity: Major
      Found in app/src/models/area.modelV2.js and 1 other location - About 2 hrs to fix
      app/src/models/area.modelV2.js on lines 92..95

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

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

          static async mergeSubscriptionOverArea(area, subscription) {
              if (area.isNew) {
                  // This is for the serializer to know that it must override the area id with the subscription id
                  area.overrideId = true;
      
      
      Severity: Major
      Found in app/src/services/subscription.service.js - About 2 hrs to fix

        Function obtainImages has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async obtainImages(groups, generateImages) {
                logger.debug('Obtaining images with gropus');
                const response = [];
                if (groups) {
                    const keys = Object.keys(groups);
        Severity: Major
        Found in app/src/services/alerts.service.js - About 2 hrs to fix

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

              admin: {
                  _id: false,
                  adm0: { type: String, required: false, trim: true },
                  adm1: { type: Number, required: false, trim: true },
                  adm2: { type: Number, required: false, trim: true }
          Severity: Major
          Found in app/src/models/area.modelV2.js and 1 other location - About 1 hr to fix
          app/src/models/area.modelV2.js on lines 32..37

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

          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

              iso: {
                  _id: false,
                  country: { type: String, required: false, trim: true },
                  region: { type: String, required: false, trim: true },
                  subregion: { type: String, required: false, trim: true },
          Severity: Major
          Found in app/src/models/area.modelV2.js and 1 other location - About 1 hr to fix
          app/src/models/area.modelV2.js on lines 38..43

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

          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 {
                      const result = await RWAPIMicroservice.requestToMicroservice({
                          uri,
                          method: 'GET',
                          headers: {
          Severity: Major
          Found in app/src/services/alerts.service.js and 1 other location - About 1 hr to fix
          app/src/services/alerts.service.js on lines 166..178

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

          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 delete has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              static async delete(ctx) {
                  logger.info(`Deleting area with id ${ctx.params.id}`);
                  const areaToDelete = await AreaModel.findById(ctx.params.id);
                  if (areaToDelete) {
                      if (areaToDelete.subscriptionId) {
          Severity: Minor
          Found in app/src/routes/api/v2/area.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 deleteByUserId has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              static async deleteByUserId(userId, apiKey) {
                  logger.debug(`[AreaService]: Delete areas for user with id:  ${userId}`);
          
                  const userAreas = await Area.find({ userId: { $eq: userId } }).exec();
          
          
          Severity: Minor
          Found in app/src/services/area.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 deleteByUserId has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              static async deleteByUserId(ctx) {
                  logger.info(`Deleting areas of user with id ${ctx.params.userId}`);
                  const userIdToDelete = ctx.params.userId;
          
                  try {
          Severity: Minor
          Found in app/src/routes/api/v2/area.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

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

                  try {
                      const result = await RWAPIMicroservice.requestToMicroservice({
                          uri,
                          method: 'GET',
                          headers: {
          Severity: Major
          Found in app/src/services/alerts.service.js and 1 other location - About 1 hr to fix
          app/src/services/alerts.service.js on lines 185..197

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

          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