Showing 44 of 126 total issues
File area.router.js
has 692 lines of code (exceeds 250 allowed). Consider refactoring. Open
const Router = require('koa-router');
const logger = require('logger');
const config = require('config');
const moment = require('moment');
const AreaSerializerV2 = require('serializers/area.serializerV2');
Function update
has a Cognitive Complexity of 73 (exceeds 5 allowed). Consider refactoring. Open
static async update(ctx) {
let previousArea = await AreaModel.findById(ctx.params.id);
let area = await AreaModel.findById(ctx.params.id);
if (!area) {
// Try to find subscription with same ID
- Read upRead up
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 save
has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring. Open
static async save(ctx) {
logger.info('Saving v2 area', ctx.request.body);
const userId = ctx.state.loggedUser.id;
let isSaved = false;
- Read upRead up
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 update
has 132 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async update(ctx) {
let previousArea = await AreaModel.findById(ctx.params.id);
let area = await AreaModel.findById(ctx.params.id);
if (!area) {
// Try to find subscription with same ID
Function save
has 130 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async save(ctx) {
logger.info('Saving v2 area', ctx.request.body);
const userId = ctx.state.loggedUser.id;
let isSaved = false;
File area.router.js
has 319 lines of code (exceeds 250 allowed). Consider refactoring. Open
const Router = require('koa-router');
const logger = require('logger');
const AreaSerializer = require('serializers/area.serializer');
const AreaModel = require('models/area.model');
const AreaValidator = require('validators/area.validator');
Function sync
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async sync(ctx) {
try {
// Default interval is the last 2 days
let startDate = moment().subtract('2', 'd').hour(0).minute(0);
let endDate = moment().hour(0).minute(0);
Function exports
has 82 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);
Function mergeSubscriptionOverArea
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
static async mergeSubscriptionOverArea(area, subscription) {
if (area.isNew) {
// This is for the serializer to know that it must override the area id with the subscription id
area.overrideId = true;
- Read upRead up
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 init
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function init() {
return new Promise((resolve, reject) => {
async function onDbReady(err) {
if (err) {
if (retries >= 0) {
Function getRequestBodyForSubscriptionFromArea
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
static getRequestBodyForSubscriptionFromArea(area) {
const body = {
name: area.name,
datasets: SubscriptionsService.getDatasetsForSubscription(area),
language: area.language,
- Read upRead up
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 obtainImages
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
static async obtainImages(groups, generateImages) {
logger.debug('Obtaining images with gropus');
const response = [];
if (groups) {
const keys = Object.keys(groups);
- Read upRead up
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 update
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
static async update(ctx) {
logger.info(`Updating area with id ${ctx.params.id}`);
const area = await AreaModel.findById(ctx.params.id);
const { files } = ctx.request;
if (ctx.request.body.application || !area.application) {
- Read upRead up
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 onDbReady
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function onDbReady(err) {
if (err) {
if (retries >= 0) {
retries--;
logger.error(`Failed to connect to MongoDB uri ${mongoUri} with error message "${err.message}", retrying...`);
Function mergeSubscriptionOverArea
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async mergeSubscriptionOverArea(area, subscription) {
if (area.isNew) {
// This is for the serializer to know that it must override the area id with the subscription id
area.overrideId = true;
Function obtainImages
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async obtainImages(groups, generateImages) {
logger.debug('Obtaining images with gropus');
const response = [];
if (groups) {
const keys = Object.keys(groups);
Function delete
has a Cognitive Complexity of 14 (exceeds 5 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) {
- Read upRead up
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 deleteByUserId
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
static async deleteByUserId(userId, apiKey) {
logger.debug(`[AreaService]: Delete areas for user with id: ${userId}`);
const userAreas = await Area.find({ userId: { $eq: userId } }).exec();
- Read upRead up
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 deleteByUserId
has a Cognitive Complexity of 14 (exceeds 5 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 {
- Read upRead up
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 update
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async update(ctx) {
logger.info(`Updating area with id ${ctx.params.id}`);
const area = await AreaModel.findById(ctx.params.id);
const { files } = ctx.request;
if (ctx.request.body.application || !area.application) {