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');
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');
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 {
- 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 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;
- 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 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;
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);
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);
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;
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));
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));
- 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 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 {
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);
- 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 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;
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();
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}`);
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();
- 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 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);
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;
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`);
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');