resource-watch/layer

View on GitHub

Showing 82 of 82 total issues

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

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

            try {
                const layer = await LayerService.get(id, ctx.request.headers['x-api-key']);
                await LayerService.delete(layer, ctx.request.headers['x-api-key']);
                ctx.set('cache-control', 'flush');
                ctx.body = LayerSerializer.serialize(layer);
    Severity: Major
    Found in app/src/routes/api/v1/layer.router.js and 1 other location - About 1 hr to fix
    app/src/routes/api/v1/layer.router.js on lines 95..110

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 67.

    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

            try {
                const layer = await LayerService.update(id, ctx.request.body, ctx.request.headers['x-api-key']);
                ctx.set('cache-control', 'flush');
                ctx.body = LayerSerializer.serialize(layer);
                ctx.set('uncache', ['layer', id, layer.slug, `${layer.dataset}-layer`, `${ctx.state.dataset.attributes.slug}-layer`, `${ctx.state.dataset.id}-layer-all`]);
    Severity: Major
    Found in app/src/routes/api/v1/layer.router.js and 1 other location - About 1 hr to fix
    app/src/routes/api/v1/layer.router.js on lines 116..132

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

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

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

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

          if (ctx.request.body.layer) {
              ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.layer);
              delete ctx.request.body.layer;
          }
      Severity: Major
      Found in app/src/routes/api/v1/layer.router.js and 1 other location - About 1 hr to fix
      app/src/routes/api/v1/layer.router.js on lines 369..372

      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 (ctx.request.body && ctx.request.body.layer) {
              ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.layer);
              delete ctx.request.body.layer;
          }
      Severity: Major
      Found in app/src/routes/api/v1/layer.router.js and 1 other location - About 1 hr to fix
      app/src/routes/api/v1/layer.router.js on lines 344..347

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

          static async create(layer, dataset, user, apiKey) {
              logger.debug(`[LayerService - create]: Getting layer with name:  ${layer.name}`);
              const tempSlug = await LayerService.getSlug(layer.name);
      
              logger.debug(`[DBACCESS-SAVE]: layer.name: ${layer.name}`);
      Severity: Minor
      Found in app/src/services/layer.service.js - About 1 hr to fix

        Function deleteByDataset has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            static async deleteByDataset(id, apiKey) {
                logger.debug(`[LayerService - deleteByDataset]: Getting layers of dataset with id:  ${id}`);
                const layers = await Layer.find({
                    dataset: id
                }).exec();
        Severity: Minor
        Found in app/src/services/layer.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 authorizationMiddleware has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const authorizationMiddleware = async (ctx, next) => {
            logger.debug(`[LayerRouter] Checking authorization`);
            // Get user from query (delete) or body (post-patch)
            const newLayerCreation = ctx.request.method === 'POST';
            const user = LayerRouter.getUser(ctx);
        Severity: Minor
        Found in app/src/routes/api/v1/layer.router.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

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

                        const result = await RWAPIMicroservice.requestToMicroservice({
                            uri: `/v1/collection/find-by-ids`,
                            method: 'POST',
                            body: {
                                ids,
            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 135..145

            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

                        const result = await RWAPIMicroservice.requestToMicroservice({
                            uri: `/v1/favourite/find-by-user`,
                            method: 'POST',
                            body: {
                                app,
            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 115..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 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

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

                static async delete(layer, apiKey) {
                    logger.debug(`[LayerService - delete]: Getting layer with id: ${layer.id}`);
                    if (!layer) {
                        logger.error(`[LayerService]: Layer with id ${layer.id} doesn't exist`);
                        throw new LayerNotFound(`Layer with id '${layer.id}' doesn't exist`);
            Severity: Minor
            Found in app/src/services/layer.service.js - About 1 hr to fix

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

                      let user = { ...(ctx.request.query.loggedUser ? JSON.parse(ctx.request.query.loggedUser) : {}), ...ctx.request.body.loggedUser };
              Severity: Major
              Found in app/src/routes/api/v1/layer.router.js and 1 other location - About 1 hr to fix
              app/src/validators/layer.validator.js on lines 9..9

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

              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/layer.router.js and 1 other location - About 1 hr to fix
              app/src/routes/api/v1/layer.router.js on lines 316..318

              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

                      return { ...(ctx.request.query.loggedUser ? JSON.parse(ctx.request.query.loggedUser) : {}), ...ctx.request.body.loggedUser };
              Severity: Major
              Found in app/src/validators/layer.validator.js and 1 other location - About 1 hr to fix
              app/src/routes/api/v1/layer.router.js on lines 38..38

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

                  static async validateCreation(koaObj) {
                      logger.info('Validating Layer Creation');
                      koaObj.checkBody('name').notEmpty().check((name) => LayerValidator.notEmptyString(name), 'can not be empty');
                      koaObj.checkBody('application').notEmpty().check((application) => LayerValidator.notEmptyArray(application), 'must be a non-empty array');
                      koaObj.checkBody('description').optional().check((description) => LayerValidator.isString(description), 'must be a string');
              Severity: Minor
              Found in app/src/validators/layer.validator.js - About 1 hr to fix
                Severity
                Category
                Status
                Source
                Language