resource-watch/widget

View on GitHub

Showing 77 of 77 total issues

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

            ctx.set('uncache', ['widget', id, widget.slug, `${widget.dataset}-widget`, `${ctx.state.dataset.slug}-widget`, `${ctx.state.dataset.id}-widget-all`]);
Severity: Major
Found in app/src/routes/api/v1/widget.router.js and 1 other location - About 2 hrs to fix
app/src/routes/api/v1/widget.router.js on lines 310..310

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

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function update has 52 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    static async update(id, widget, apiKey) {
        logger.debug(`[WidgetService]: Updating widget with id:  ${id}`);
        const currentWidget = await Widget.findById(id).exec() || await Widget.findOne({
            slug: id
        }).exec();
Severity: Major
Found in app/src/services/widget.service.js - About 2 hrs to fix

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

        static async update(id, widget, apiKey) {
            logger.debug(`[WidgetService]: Updating widget with id:  ${id}`);
            const currentWidget = await Widget.findById(id).exec() || await Widget.findOne({
                slug: id
            }).exec();
    Severity: Minor
    Found in app/src/services/widget.service.js - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function exports has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    module.exports = (() => {
    
        const loadAPI = (app, path, pathApi) => {
            const routesFiles = fs.readdirSync(path);
            let existIndexRouter = false;
    Severity: Minor
    Found in app/src/loader.js - About 1 hr to fix

      Function authorizationMiddleware has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const authorizationMiddleware = async (ctx, next) => {
          logger.debug(`[WidgetRouter] Checking authorization`);
          // Get user from query (delete) or body (post-patch)
          const newWidgetCreation = ctx.request.path.includes('widget') && ctx.request.method === 'POST' && !(ctx.request.path.includes('find-by-ids'));
          const newWidgetUpdate = ctx.request.path.includes('widget') && ctx.request.method === 'PATCH';
      Severity: Minor
      Found in app/src/routes/api/v1/widget.router.js - About 1 hr to fix

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

                if (newWidgetUpdate || newWidgetClone) {
                    const permission = await WidgetService.hasPermission(ctx.params.widget, user, ctx.request.headers['x-api-key']);
                    if (!permission) {
                        ctx.throw(403, 'Forbidden');
                        return;
        Severity: Major
        Found in app/src/routes/api/v1/widget.router.js and 1 other location - About 1 hr to fix
        app/src/routes/api/v1/widget.router.js on lines 481..487

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

        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

                koaObj.checkBody('application')
                    .notEmpty()
                    .check((v) => WidgetValidator.isArray(v), 'must be an array')
                    .check((v) => v.length !== 0, `can't be an empty array`);
        Severity: Major
        Found in app/src/validators/widget.validator.js and 1 other location - About 1 hr to fix
        app/src/validators/widget.validator.js on lines 124..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 65.

        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 ((user.role === 'MANAGER' || user.role === 'ADMIN') && !newWidgetCreation) {
                const permission = await WidgetService.hasPermission(ctx.params.widget, user, ctx.request.headers['x-api-key']);
                if (!permission) {
                    ctx.throw(403, 'Forbidden');
                    return;
        Severity: Major
        Found in app/src/routes/api/v1/widget.router.js and 1 other location - About 1 hr to fix
        app/src/routes/api/v1/widget.router.js on lines 465..471

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

        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 result = await RWAPIMicroservice.requestToMicroservice({
                        uri: `/v1/collection/find-by-ids`,
                        method: 'POST',
                        json: true,
                        body: {
        Severity: Major
        Found in app/src/services/relationships.service.js and 1 other location - About 1 hr to fix
        app/src/services/relationships.service.js on lines 157..168

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

        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 result = await RWAPIMicroservice.requestToMicroservice({
                        uri: `/v1/favourite/find-by-user`,
                        method: 'POST',
                        json: true,
                        body: {
        Severity: Major
        Found in app/src/services/relationships.service.js and 1 other location - About 1 hr to fix
        app/src/services/relationships.service.js on lines 114..125

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

        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

                koaObj.checkBody('application')
                    .optional()
                    .check((v) => WidgetValidator.isArray(v), 'must be an array')
                    .check((v) => v.length !== 0, `can't be an empty array`);
        Severity: Major
        Found in app/src/validators/widget.validator.js and 1 other location - About 1 hr to fix
        app/src/validators/widget.validator.js on lines 62..65

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

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Function create has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async create(widget, datasetId, dataset, userId, apiKey) {
                logger.debug(`[WidgetService]: Creating widget with name: ${widget.name}`);
                const tempSlug = await WidgetService.getSlug(widget.name);
        
                const newWidget = await new Widget({
        Severity: Minor
        Found in app/src/services/widget.service.js - About 1 hr to fix

          Function clone has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              static async clone(id, widget, userId, apiKey) {
                  logger.debug(`[WidgetService]: Getting widget with id: ${id}`);
                  logger.debug(`[WidgetService]: New user id: ${userId}`);
                  const currentWidget = await Widget.findById(id).exec() || await Widget.findOne({
                      slug: id
          Severity: Minor
          Found in app/src/services/widget.service.js - About 1 hr to fix

            Function serializeElement has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static serializeElement(el) {
                    return {
                        id: el._id,
                        type: 'widget',
                        attributes: {
            Severity: Minor
            Found in app/src/serializers/widget.serializer.js - About 1 hr to fix

              Function loadAPI has 32 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  const loadAPI = (app, path, pathApi) => {
                      const routesFiles = fs.readdirSync(path);
                      let existIndexRouter = false;
                      routesFiles.forEach((file) => {
                          const newPath = path ? (`${path}/${file}`) : file;
              Severity: Minor
              Found in app/src/loader.js - About 1 hr to fix

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

                                        if (pathApi) {
                                            app.use(mount(pathApi, require(newPath).middleware()));
                                        } else {
                                            app.use(require(newPath).middleware());
                                        }
                Severity: Major
                Found in app/src/loader.js and 1 other location - About 1 hr to fix
                app/src/loader.js on lines 42..46

                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

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

                            if (pathApi) {
                                app.use(mount(pathApi, require(newPath).middleware()));
                            } else {
                                app.use(require(newPath).middleware());
                            }
                Severity: Major
                Found in app/src/loader.js and 1 other location - About 1 hr to fix
                app/src/loader.js on lines 25..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 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 (typeof resource.ids === 'string') {
                            resource.ids = resource.ids.split(',').map((elem) => elem.trim());
                        }
                Severity: Major
                Found in app/src/routes/api/v1/widget.router.js and 1 other location - About 1 hr to fix
                app/src/routes/api/v1/widget.router.js on lines 328..330

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

                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 (typeof resource.env === 'string') {
                            resource.env = resource.env.split(',').map((elem) => elem.trim());
                        }
                Severity: Major
                Found in app/src/routes/api/v1/widget.router.js and 1 other location - About 1 hr to fix
                app/src/routes/api/v1/widget.router.js on lines 325..327

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

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Function validationMiddleware has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const validationMiddleware = async (ctx, next) => {
                    logger.debug(`[WidgetRouter] Validating the widget`);
                    if (ctx.request.body.widget) {
                        ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.widget);
                        delete ctx.request.body.widget;
                Severity: Minor
                Found in app/src/routes/api/v1/widget.router.js - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language