resource-watch/layer

View on GitHub

Showing 33 of 82 total issues

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

const Router = require('koa-router');
const logger = require('logger');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
const LayerModel = require('models/layer.model');
const LayerService = require('services/layer.service');
Severity: Minor
Found in app/src/routes/api/v1/layer.router.js - About 6 hrs to fix

    File layer.service.js has 401 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const logger = require('logger');
    const Layer = require('models/layer.model');
    const GraphService = require('services/graph.service');
    const LayerNotFound = require('errors/layerNotFound.error');
    const LayerProtected = require('errors/layerProtected.error');
    Severity: Minor
    Found in app/src/services/layer.service.js - About 5 hrs to fix

      Function getRelationships has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          static async getRelationships(layers, includes, user, query = {}, apiKey) {
              logger.info(`Getting relationships of layers: ${layers}`);
              // eslint-disable-next-line no-plusplus
              for (let i = 0; i < layers.length; i++) {
                  try {
      Severity: Minor
      Found in app/src/services/relationships.service.js - About 3 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 getAll has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          static async getAll(ctx) {
              logger.info(`[LayerRouter] Getting all layers`);
              const { query } = ctx;
              const dataset = ctx.params.dataset || null;
              const user = ctx.query.loggedUser && ctx.query.loggedUser !== 'null' ? JSON.parse(ctx.query.loggedUser) : null;
      Severity: Minor
      Found in app/src/routes/api/v1/layer.router.js - About 3 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 getAll has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static async getAll(ctx) {
              logger.info(`[LayerRouter] Getting all layers`);
              const { query } = ctx;
              const dataset = ctx.params.dataset || null;
              const user = ctx.query.loggedUser && ctx.query.loggedUser !== 'null' ? JSON.parse(ctx.query.loggedUser) : null;
      Severity: Major
      Found in app/src/routes/api/v1/layer.router.js - About 2 hrs to fix

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

        module.exports = (grunt) => {
        
            grunt.file.setBase('..');
            // eslint-disable-next-line import/no-extraneous-dependencies
            require('load-grunt-tasks')(grunt);
        Severity: Major
        Found in app/Gruntfile.js - About 2 hrs to fix

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

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

            Function getFilteredQuery has 62 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static getFilteredQuery(query, ids = []) {
                    const { collection } = query;
                    const { favourite } = query;
                    if (!query.application && query.app) {
                        query.application = query.app;
            Severity: Major
            Found in app/src/services/layer.service.js - About 2 hrs to fix

              Function onDbReady has 57 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      async function onDbReady(err) {
                          if (err) {
                              logger.error('MongoURI', mongoUri);
                              logger.error(err);
                              reject(new Error(err));
              Severity: Major
              Found in app/src/app.js - About 2 hrs to fix

                Function serialize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                    static serialize(data, link = null, forceArray = false) {
                        const result = {};
                        if (data) {
                            if (data.docs) {
                                result.data = data.docs.map((el) => LayerSerializer.serializeElement(el));
                Severity: Minor
                Found in app/src/serializers/layer.serializer.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 getRelationships has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    static async getRelationships(layers, includes, user, query = {}, apiKey) {
                        logger.info(`Getting relationships of layers: ${layers}`);
                        // eslint-disable-next-line no-plusplus
                        for (let i = 0; i < layers.length; i++) {
                            try {
                Severity: Minor
                Found in app/src/services/relationships.service.js - About 1 hr to fix

                  Function authorizationMiddleware has a Cognitive Complexity of 14 (exceeds 5 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

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

                      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

                            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

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

                                  static serialize(data, link = null, forceArray = false) {
                                      const result = {};
                                      if (data) {
                                          if (data.docs) {
                                              result.data = data.docs.map((el) => LayerSerializer.serializeElement(el));
                              Severity: Minor
                              Found in app/src/serializers/layer.serializer.js - About 1 hr to fix
                                Severity
                                Category
                                Status
                                Source
                                Language