resource-watch/layer

View on GitHub

Showing 33 of 82 total issues

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

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

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

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

        Function getByDataset has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async getByDataset(resource) {
                logger.debug(`[LayerService - getByDataset] Getting layers for datasets with ids ${resource.ids}`);
                if (resource.app) {
                    if (resource.app.indexOf('@') >= 0) {
                        resource.app = {
        Severity: Minor
        Found in app/src/services/layer.service.js - About 1 hr to fix

          Function exports has a Cognitive Complexity of 9 (exceeds 5 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 55 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 get has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              static async get(ctx) {
                  const id = ctx.params.layer;
                  logger.info(`[LayerRouter] Getting layer with id: ${id}`);
                  const includes = ctx.query.includes ? ctx.query.includes.split(',').map((elem) => elem.trim()) : [];
                  const { query } = ctx;
          Severity: Minor
          Found in app/src/routes/api/v1/layer.router.js - About 35 mins to fix

          Cognitive Complexity

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

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

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

          Further reading

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

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

          Cognitive Complexity

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

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

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

          Further reading

          Function delete has a Cognitive Complexity of 7 (exceeds 5 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 35 mins to fix

          Cognitive Complexity

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

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

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

          Further reading

          Avoid too many return statements within this function.
          Open

                      return;
          Severity: Major
          Found in app/src/routes/api/v1/layer.router.js - About 30 mins to fix

            Function getAll has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                static async getAll(query = {}, dataset = null, user, apiKey) {
                    logger.debug(`[LayerService - getAll]: Getting all layers`);
                    const sort = query.sort || '';
                    const page = query['page[number]'] ? parseInt(query['page[number]'], 10) : 1;
                    const limit = query['page[size]'] ? parseInt(query['page[size]'], 10) : 10;
            Severity: Minor
            Found in app/src/services/layer.service.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 checkDataset has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                static async checkDataset(ctx) {
                    if (ctx.params.dataset || ctx.request.body.dataset) {
                        const datasetId = ctx.params.dataset || ctx.request.body.dataset;
                        logger.info(`[DatasetService] Validating presence of dataset with id: ${datasetId}`);
            
            
            Severity: Minor
            Found in app/src/services/dataset.service.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 getByDataset has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                static async getByDataset(resource) {
                    logger.debug(`[LayerService - getByDataset] Getting layers for datasets with ids ${resource.ids}`);
                    if (resource.app) {
                        if (resource.app.indexOf('@') >= 0) {
                            resource.app = {
            Severity: Minor
            Found in app/src/services/layer.service.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 validationMiddleware has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

            const validationMiddleware = async (ctx, next) => {
                logger.debug(`[LayerRouter] Validating`);
                if (ctx.request.body.layer) {
                    ctx.request.body = Object.assign(ctx.request.body, ctx.request.body.layer);
                    delete ctx.request.body.layer;
            Severity: Minor
            Found in app/src/routes/api/v1/layer.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

            Severity
            Category
            Status
            Source
            Language