gfw-api/gfw-area

View on GitHub

Showing 44 of 126 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

    Function get has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        static async get(ctx) {
            logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
    
            if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                ctx.throw(404, 'Area not found');
    Severity: Minor
    Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

      Function getRequestBodyForSubscriptionFromArea has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          static getRequestBodyForSubscriptionFromArea(area) {
              const body = {
                  name: area.name,
                  datasets: SubscriptionsService.getDatasetsForSubscription(area),
                  language: area.language,
      Severity: Minor
      Found in app/src/services/subscription.service.js - About 1 hr to fix

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

            static async get(ctx) {
                logger.info(`Obtaining v2 area with areaId ${ctx.params.id}`);
        
                if (!mongoose.Types.ObjectId.isValid(ctx.params.id)) {
                    ctx.throw(404, 'Area not found');
        Severity: Minor
        Found in app/src/routes/api/v2/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 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 groupPoints has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            static groupPoints(dataViirs, dataGlad, precisionBbox) {
                logger.debug('Group points', ' and precisionBbox ', precisionBbox);
                const result = {};
                if (dataViirs) {
                    for (let i = 0, { length } = dataViirs; i < length; i++) {
        Severity: Minor
        Found in app/src/services/alerts.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 groupPoints has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static groupPoints(dataViirs, dataGlad, precisionBbox) {
                logger.debug('Group points', ' and precisionBbox ', precisionBbox);
                const result = {};
                if (dataViirs) {
                    for (let i = 0, { length } = dataViirs; i < length; i++) {
        Severity: Minor
        Found in app/src/services/alerts.service.js - About 1 hr to fix

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

              static async update(ctx, next) {
                  logger.debug('Validating body for update area');
                  ctx.checkBody('name').optional().len(2, 100);
                  ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
          
          
          Severity: Minor
          Found in app/src/validators/area.validatorV2.js - About 1 hr to fix

            Function deleteByUserId has 36 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                static async deleteByUserId(ctx) {
                    logger.info(`Deleting areas of user with id ${ctx.params.userId}`);
                    const userIdToDelete = ctx.params.userId;
            
                    try {
            Severity: Minor
            Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

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

                  static async delete(ctx) {
                      logger.info(`Deleting area with id ${ctx.params.id}`);
                      const areaToDelete = await AreaModel.findById(ctx.params.id);
                      if (areaToDelete) {
                          if (areaToDelete.subscriptionId) {
              Severity: Minor
              Found in app/src/routes/api/v2/area.router.js - About 1 hr to fix

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

                    static getFilteredQuery(query, ids = []) {
                        const areaAttributes = Object.keys(Area.schema.obj);
                        logger.debug(`[getFilteredQuery] areaAttributes: ${areaAttributes}`);
                        Object.keys(query).forEach((param) => {
                            if (areaAttributes.indexOf(param) < 0) {
                Severity: Minor
                Found in app/src/services/area.service.js - About 1 hr to fix

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

                      static async create(ctx, next) {
                          logger.debug('Validating body for create area');
                          ctx.checkBody('name').notEmpty().len(1, 100);
                          ctx.checkBody('application').optional().check((application) => AreaValidatorV2.notEmptyString(application), 'cannot be empty');
                  
                  
                  Severity: Minor
                  Found in app/src/validators/area.validatorV2.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 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 updateByGeostore has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            static async updateByGeostore(ctx) {
                                const geostores = ctx.request.body.geostores || [];
                                const updateParams = ctx.request.body.update_params || {};
                                logger.info('Updating geostores: ', geostores);
                                logger.info('Updating with params: ', updateParams);
                        Severity: Minor
                        Found in app/src/routes/api/v2/area.router.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 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 serialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              static serialize(data, link = null) {
                                  const serializedData = link !== null ? areaSerializer.serialize(data.docs) : areaSerializer.serialize(data);
                          
                                  if (serializedData.data && Array.isArray(serializedData.data)) {
                                      serializedData.data.forEach((el, idx) => {
                          Severity: Minor
                          Found in app/src/serializers/area.serializerV2.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 getFilters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                          function getFilters(ctx) {
                              const filter = shouldUseAllFilter(ctx) ? {} : { userId: ctx.state.loggedUser.id };
                          
                              const { query } = ctx;
                              if (query.application) {
                          Severity: Minor
                          Found in app/src/routes/api/v2/area.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 serialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              static serialize(data, link = null) {
                                  let result;
                                  if (data.docs) {
                                      result = areaSerializer.serialize(data.docs);
                                  } else {
                          Severity: Minor
                          Found in app/src/serializers/area.serializer.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

                          Severity
                          Category
                          Status
                          Source
                          Language