gfw-api/gfw-area

View on GitHub
app/src/routes/api/v2/area.router.js

Summary

Maintainability
F
1 wk
Test Coverage
A
91%

File area.router.js has 692 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const Router = require('koa-router');
const logger = require('logger');
const config = require('config');
const moment = require('moment');
const AreaSerializerV2 = require('serializers/area.serializerV2');
Severity: Major
Found in app/src/routes/api/v2/area.router.js - About 1 day to fix

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

        static async update(ctx) {
            let previousArea = await AreaModel.findById(ctx.params.id);
            let area = await AreaModel.findById(ctx.params.id);
            if (!area) {
                // Try to find subscription with same ID
    Severity: Minor
    Found in app/src/routes/api/v2/area.router.js - About 1 day 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 save has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
    Open

        static async save(ctx) {
            logger.info('Saving v2 area', ctx.request.body);
            const userId = ctx.state.loggedUser.id;
            let isSaved = false;
    
    
    Severity: Minor
    Found in app/src/routes/api/v2/area.router.js - About 1 day 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 132 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async update(ctx) {
            let previousArea = await AreaModel.findById(ctx.params.id);
            let area = await AreaModel.findById(ctx.params.id);
            if (!area) {
                // Try to find subscription with same ID
    Severity: Major
    Found in app/src/routes/api/v2/area.router.js - About 5 hrs to fix

      Function save has 130 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async save(ctx) {
              logger.info('Saving v2 area', ctx.request.body);
              const userId = ctx.state.loggedUser.id;
              let isSaved = false;
      
      
      Severity: Major
      Found in app/src/routes/api/v2/area.router.js - About 5 hrs to fix

        Function sync has 87 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async sync(ctx) {
                try {
                    // Default interval is the last 2 days
                    let startDate = moment().subtract('2', 'd').hour(0).minute(0);
                    let endDate = moment().hour(0).minute(0);
        Severity: Major
        Found in app/src/routes/api/v2/area.router.js - About 3 hrs to fix

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

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

              static async get(ctx) {
                  logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
          
                  if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                      ctx.throw(404, 'Area not found');
          Severity: Minor
          Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

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

                static async get(ctx) {
                    logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
            
                    if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                        ctx.throw(404, 'Area not found');
            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 36 lines of code (exceeds 25 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

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

                Function updateByGeostore has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async updateByGeostore(ctx) {
                        const geostores = ctx.request.body.geostores || [];
                        const updateParams = ctx.request.body.update_params || {};
                        logger.info('Updating geostores: ', geostores);
                        logger.info('Updating with params: ', updateParams);
                Severity: Minor
                Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

                  Function getFilters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function getFilters(ctx) {
                      const filter = shouldUseAllFilter(ctx) ? {} : { userId: ctx.state.loggedUser.id };
                  
                      const { query } = ctx;
                      if (query.application) {
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js - About 35 mins 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 loggedUserToState has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  async function loggedUserToState(ctx, next) {
                      if (ctx.query && ctx.query.loggedUser) {
                          ctx.state.loggedUser = JSON.parse(ctx.query.loggedUser);
                          delete ctx.query.loggedUser;
                      } else if (ctx.request.body && ctx.request.body.loggedUser) {
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js - About 25 mins 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 unwrapJSONStrings has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                  async function unwrapJSONStrings(ctx, next) {
                      if (ctx.request.body.use && typeof ctx.request.body.use === 'string' && ctx.request.body.use.length > 0) {
                          try {
                              ctx.request.body.use = JSON.parse(ctx.request.body.use);
                          } catch (e) {
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js - About 25 mins 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

                  async function unwrapJSONStrings(ctx, next) {
                      if (ctx.request.body.use && typeof ctx.request.body.use === 'string' && ctx.request.body.use.length > 0) {
                          try {
                              ctx.request.body.use = JSON.parse(ctx.request.body.use);
                          } catch (e) {
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 day to fix
                  app/src/routes/api/v1/area.router.js on lines 312..329

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

                  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

                  function getFilteredSort(sort) {
                      const sortParams = sort.split(',');
                      const filteredSort = {};
                      const areaAttributes = Object.keys(AreaModel.schema.obj);
                      sortParams.forEach((param) => {
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 6 hrs to fix
                  app/src/services/area.service.js on lines 73..89

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

                  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 isOwnerAdminOrMicroservice = async (ctx, next) => {
                      logger.debug(`[AreaRouter] Checking access to resources by ownership, ADMIN role or microservice token`);
                  
                      const user = ctx.state.loggedUser;
                      const userFromParam = ctx.params.userId;
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 4 hrs to fix
                  app/src/routes/api/v1/area.router.js on lines 331..348

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

                  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

                      } else if (ctx.request.body && ctx.request.body.loggedUser) {
                          if (typeof ctx.request.body.loggedUser === 'object') {
                              ctx.state.loggedUser = ctx.request.body.loggedUser;
                          } else {
                              ctx.state.loggedUser = JSON.parse(ctx.request.body.loggedUser);
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 3 hrs to fix
                  app/src/routes/api/v1/area.router.js on lines 274..287

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

                  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 5 locations. Consider refactoring.
                  Open

                          if (ctx.request.body.use) {
                              use.id = ctx.request.body.use ? ctx.request.body.use.id : null;
                              use.name = ctx.request.body.use ? ctx.request.body.use.name : null;
                          }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 4 other locations - About 3 hrs to fix
                  app/src/routes/api/v1/area.router.js on lines 129..132
                  app/src/routes/api/v1/area.router.js on lines 134..137
                  app/src/routes/api/v1/area.router.js on lines 177..180
                  app/src/routes/api/v1/area.router.js on lines 183..186

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

                  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 getHostForPaginationLink = (ctx) => {
                      if ('x-rw-domain' in ctx.request.header) {
                          return ctx.request.header['x-rw-domain'];
                      }
                      if ('referer' in ctx.request.header) {
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 3 hrs to fix
                  app/src/routes/api/v1/area.router.js on lines 20..29

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

                  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

                          if (body.iso) {
                              iso.country = body.iso ? body.iso.country : null;
                              iso.region = body.iso ? body.iso.region : null;
                          }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                  app/src/routes/api/v2/area.router.js on lines 404..407

                  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 (body.use) {
                              use.id = body.use ? body.use.id : null;
                              use.name = body.use ? body.use.name : null;
                          }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                  app/src/routes/api/v2/area.router.js on lines 410..413

                  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

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

                  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

                      } else if (ctx.request.body.fields && ctx.request.body.fields.loggedUser) {
                          ctx.state.loggedUser = JSON.parse(ctx.request.body.fields.loggedUser);
                          delete ctx.request.body.loggedUser;
                      }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                  app/src/routes/api/v1/area.router.js on lines 281..287

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

                  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 (ctx.query.startDate && moment(ctx.query.startDate).isValid()) {
                                  startDate = moment(ctx.query.startDate);
                              }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                  app/src/routes/api/v2/area.router.js on lines 640..642

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

                  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 (ctx.query.endDate && moment(ctx.query.endDate).isValid()) {
                                  endDate = moment(ctx.query.endDate);
                              }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 1 hr to fix
                  app/src/routes/api/v2/area.router.js on lines 636..638

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

                  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 4 locations. Consider refactoring.
                  Open

                              try {
                                  team = await TeamService.getTeamByUserId(userIdToDelete, ctx.request.headers['x-api-key']);
                              } catch (e) {
                                  logger.error(e);
                              }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 3 other locations - About 1 hr to fix
                  app/src/routes/api/v1/area.router.js on lines 69..73
                  app/src/routes/api/v1/area.router.js on lines 91..95
                  app/src/routes/api/v2/area.router.js on lines 521..525

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

                  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 4 locations. Consider refactoring.
                  Open

                          try {
                              team = await TeamService.getTeamByUserId(userId, ctx.request.headers['x-api-key']);
                          } catch (e) {
                              logger.error(e);
                          }
                  Severity: Major
                  Found in app/src/routes/api/v2/area.router.js and 3 other locations - About 1 hr to fix
                  app/src/routes/api/v1/area.router.js on lines 69..73
                  app/src/routes/api/v1/area.router.js on lines 91..95
                  app/src/routes/api/v2/area.router.js on lines 573..577

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

                  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.query && ctx.query.loggedUser) {
                          ctx.state.loggedUser = JSON.parse(ctx.query.loggedUser);
                          delete ctx.query.loggedUser;
                      } else if (ctx.request.body && ctx.request.body.loggedUser) {
                          if (typeof ctx.request.body.loggedUser === 'object') {
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 40 mins to fix
                  app/src/routes/api/v1/area.router.js on lines 271..287

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

                  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 (files && files.image && files.image.s3Url) {
                              area.image = files.image.s3Url;
                          }
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 35 mins to fix
                  app/src/routes/api/v1/area.router.js on lines 191..193

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

                  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.request.files && ctx.request.files.image && ctx.request.files.image.s3Url) {
                              image = ctx.request.files.image.s3Url;
                          }
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 35 mins to fix
                  app/src/routes/api/v1/area.router.js on lines 121..123

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

                  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.request.body.datasets) {
                              datasets = JSON.parse(ctx.request.body.datasets);
                          }
                  Severity: Minor
                  Found in app/src/routes/api/v2/area.router.js and 1 other location - About 35 mins to fix
                  app/src/routes/api/v1/area.router.js on lines 125..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 46.

                  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

                  There are no issues that match your filters.

                  Category
                  Status