Showing 60 of 122 total issues
File dataset.service.js
has 724 lines of code (exceeds 250 allowed). Consider refactoring. Open
const { URL } = require('url');
const { default: logger } = require('logger');
const Dataset = require('models/dataset.model');
const RelationshipsService = require('services/relationships.service');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
File dataset.router.js
has 575 lines of code (exceeds 250 allowed). Consider refactoring. Open
const Router = require('koa-router');
const koaMulter = require('koa-multer');
const { default: logger } = require('logger');
const xor = require('lodash/xor');
const DatasetService = require('services/dataset.service');
Function getAll
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
static async getAll(ctx) {
logger.info(`[DatasetRouter] Getting all datasets`);
const user = DatasetRouter.getUser(ctx);
const { query } = ctx;
const { search } = query;
- 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 41 (exceeds 5 allowed). Consider refactoring. Open
static async update(id, dataset, user, apiKey) {
logger.debug(`[DatasetService]: Getting dataset with id: ${id}`);
logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
- 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 117 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async getAll(ctx) {
logger.info(`[DatasetRouter] Getting all datasets`);
const user = DatasetRouter.getUser(ctx);
const { query } = ctx;
const { search } = query;
File relationships.service.js
has 350 lines of code (exceeds 250 allowed). Consider refactoring. Open
const { default: logger } = require('logger');
const { RWAPIMicroservice } = require('rw-api-microservice-node');
const { INCLUDES } = require('app.constants');
const { compact, uniq, startsWith, pickBy } = require('lodash');
const InvalidRequest = require('errors/invalidRequest.error');
Function update
has 108 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async update(id, dataset, user, apiKey) {
logger.debug(`[DatasetService]: Getting dataset with id: ${id}`);
logger.info(`[DBACCESS-FIND]: dataset.id: ${id}`);
const currentDataset = await Dataset.findById(id).exec() || await Dataset.findOne({
Function getResources
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
static async getResources(ids, includes, apiKey, query = '', users = [], isAdmin = false) {
logger.info(`Getting resources of ids: ${ids}`);
delete query.ids;
delete query.usersRole;
let resources = includes.map(async (include) => {
- 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 getResources
has 89 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async getResources(ids, includes, apiKey, query = '', users = [], isAdmin = false) {
logger.info(`Getting resources of ids: ${ids}`);
delete query.ids;
delete query.usersRole;
let resources = includes.map(async (include) => {
Function create
has 87 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async create(dataset, user, apiKey) {
logger.debug(`[DatasetService]: Getting dataset with name: ${dataset.name}`);
logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
const tempSlug = await DatasetService.getSlug(dataset.name);
// Check if raw dataset
Function create
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
static async create(dataset, user, apiKey) {
logger.debug(`[DatasetService]: Getting dataset with name: ${dataset.name}`);
logger.info(`[DBACCES-FIND]: dataset.name: ${dataset.name}`);
const tempSlug = await DatasetService.getSlug(dataset.name);
// Check if raw dataset
- 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
DatasetService
has 28 functions (exceeds 20 allowed). Consider refactoring. Open
class DatasetService {
// eslint-disable-next-line consistent-return
static async getSlug(name) {
const valid = false;
Function getFilteredQuery
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
static getFilteredQuery(query, ids = []) {
const { collection, favourite } = query;
if (!query.application && query.app) {
query.application = query.app;
if (favourite) {
File dataset.validator.js
has 286 lines of code (exceeds 250 allowed). Consider refactoring. Open
const { default: logger } = require('logger');
const DatasetNotValid = require('errors/datasetNotValid.error');
const { CONNECTOR_TYPES } = require('app.constants');
const { RASDAMAN_TYPES } = require('app.constants');
const { URL } = require('url');
Function init
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
const init: () => Promise<IInit> = async (): Promise<IInit> => {
return new Promise((resolve, reject) => {
async function onDbReady(err: Error): Promise<void> {
if (err) {
if (retries >= 0) {
Function onDbReady
has 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
async function onDbReady(err: Error): Promise<void> {
if (err) {
if (retries >= 0) {
retries--;
logger.error(`Failed to connect to MongoDB uri ${mongoUri}, retrying...`);
Function checkConnectorUrl
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
static checkConnectorUrl(connectorUrl, koaObj) {
let validation = false;
const {
connectorType, provider, data, tableName, sources
} = koaObj.request.body;
- 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 delete
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
static async delete(dataset, user, apiKey, applicationBasedDelete = true) {
logger.debug(`[DatasetService]: Getting dataset with id: ${dataset.id}`);
logger.info(`[DBACCESS-FIND]: dataset.id: ${dataset.id}`);
const id = dataset.id;
if (!dataset) {
Function serialize
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
static serialize(data, link = null) {
const result = {};
if (data && Array.isArray(data) && data.length === 0) {
result.data = [];
return result;
- 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 resources
has 50 lines of code (exceeds 25 allowed). Consider refactoring. Open
let resources = includes.map(async (include) => {
const obj = {};
if (INCLUDES.indexOf(include) >= 0) {
let uri = '/v1';
let payload = {