gfw-api/gfw-area

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

Summary

Maintainability
F
1 wk
Test Coverage
C
79%

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

const Router = require('koa-router');
const logger = require('logger');
const AreaSerializer = require('serializers/area.serializer');
const AreaModel = require('models/area.model');
const AreaValidator = require('validators/area.validator');
Severity: Minor
Found in app/src/routes/api/v1/area.router.js - About 3 hrs to fix

    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

    Function update has 42 lines of code (exceeds 25 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 1 hr to fix

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

          static async saveArea(ctx, userId) {
              logger.info('Saving area');
              let image = '';
              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/v1/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 saveArea has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async saveArea(ctx, userId) {
              logger.info('Saving area');
              let image = '';
              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/v1/area.router.js - About 1 hr to fix

        Function loggedUserToState has a Cognitive Complexity of 8 (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/v1/area.router.js - About 45 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/v1/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 delete has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            static async delete(ctx) {
                logger.info(`Deleting area with id ${ctx.params.id}`);
                const userId = ctx.state.loggedUser.id;
                let team = null;
                try {
        Severity: Minor
        Found in app/src/routes/api/v1/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/v1/area.router.js and 1 other location - About 1 day to fix
        app/src/routes/api/v2/area.router.js on lines 774..791

        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

        const deleteResourceAuthorizationMiddleware = async (ctx, next) => {
            logger.info(`[VocabularyRouter] Checking delete by user authorization`);
        
            const user = ctx.state.loggedUser;
            const userFromParam = ctx.params.userId;
        Severity: Major
        Found in app/src/routes/api/v1/area.router.js and 1 other location - About 4 hrs to fix
        app/src/routes/api/v2/area.router.js on lines 802..819

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

        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/v1/area.router.js and 4 other locations - About 3 hrs to fix
        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
        app/src/routes/api/v2/area.router.js on lines 221..224

        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

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

                if (ctx.request.body.iso) {
                    iso.country = ctx.request.body.iso ? ctx.request.body.iso.country : null;
                    iso.region = ctx.request.body.iso ? ctx.request.body.iso.region : null;
                }
        Severity: Major
        Found in app/src/routes/api/v1/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 177..180
        app/src/routes/api/v1/area.router.js on lines 183..186
        app/src/routes/api/v2/area.router.js on lines 221..224

        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

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

                if (ctx.request.body.iso) {
                    iso.country = ctx.request.body.iso ? ctx.request.body.iso.country : null;
                    iso.region = ctx.request.body.iso ? ctx.request.body.iso.region : null;
                }
        Severity: Major
        Found in app/src/routes/api/v1/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/v2/area.router.js on lines 221..224

        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

        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/v1/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 183..186
        app/src/routes/api/v2/area.router.js on lines 221..224

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

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

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

        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;
            } else {
                ctx.throw(401, 'Unauthorized');
        Severity: Major
        Found in app/src/routes/api/v1/area.router.js and 1 other location - About 1 hr to fix
        app/src/routes/api/v2/area.router.js on lines 749..752

        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 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/v1/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/v2/area.router.js on lines 521..525
        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

        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/v1/area.router.js and 3 other locations - About 1 hr to fix
        app/src/routes/api/v1/area.router.js on lines 91..95
        app/src/routes/api/v2/area.router.js on lines 521..525
        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/v1/area.router.js and 1 other location - About 40 mins to fix
        app/src/routes/api/v2/area.router.js on lines 739..752

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

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

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

        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

                const query = {
                    $or: [
                        { userId },
                        { _id: { $in: teamAreas } }
                    ],
        Severity: Minor
        Found in app/src/routes/api/v1/area.router.js and 1 other location - About 30 mins to fix
        app/src/routes/api/v1/area.router.js on lines 75..81

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

        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 query = {
                    $or: [
                        { userId },
                        { _id: { $in: teamAreas } }
                    ],
        Severity: Minor
        Found in app/src/routes/api/v1/area.router.js and 1 other location - About 30 mins to fix
        app/src/routes/api/v1/area.router.js on lines 97..103

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

        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