Showing 60 of 122 total issues
Consider simplifying this complex logical expression. Open
Open
} else if (connectorType === 'rest' && (provider === 'gee' || provider === 'bigquery' || provider === 'nexgddp' || provider === 'loca')) {
// is it tableName valid?
if (DatasetValidator.notEmptyString(tableName)) {
validation = true;
// if tableName not provided
Function validateCreation
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async validateCreation(koaObj) {
logger.info('Validating Dataset Creation');
koaObj.checkBody('name').notEmpty().check((name) => DatasetValidator.notEmptyString(name), 'can not be empty');
koaObj.checkBody('type').optional().check((type) => DatasetValidator.isString(type), 'must be a string');
koaObj.checkBody('subtitle').optional().check((subtitle) => DatasetValidator.isString(subtitle), 'must be a string');
Function authorizationMiddleware
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
Open
const authorizationMiddleware = async (ctx, next) => {
logger.info(`[DatasetRouter] Checking authorization`);
// Get user from query (delete) or body (post-patch)
const newDatasetCreation = ctx.request.path === '/dataset' && ctx.request.method === 'POST';
const uploadDataset = ctx.request.path.indexOf('upload') >= 0 && ctx.request.method === 'POST';
- 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 serializeElement
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static serializeElement(el) {
return {
id: el._id,
type: 'dataset',
attributes: {
Function getAll
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async getAll(apiKey, query = {}, isAdmin = false) {
logger.debug(`[DatasetService]: Getting all datasets`);
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;
Function exports
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = (() => {
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
Function notifyAdapter
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async notifyAdapter(ctx, dataset) {
const { connectorType, provider } = dataset;
const clonedDataset = { ...dataset.toObject() };
clonedDataset.id = dataset._id;
clonedDataset.connector_url = dataset.connectorUrl;
Function validateUpdate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async validateUpdate(koaObj) {
logger.info('Validating Dataset Update');
koaObj.checkBody('name').optional().check((name) => DatasetValidator.notEmptyString(name), 'can not be empty');
koaObj.checkBody('type').optional().check((type) => DatasetValidator.isString(type), 'must be a string');
koaObj.checkBody('subtitle').optional().check((subtitle) => DatasetValidator.isString(subtitle), 'must be a string');
Function clone
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async clone(id, dataset, user, apiKey, fullCloning = false) {
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({
slug: id
Function authorizationMiddleware
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const authorizationMiddleware = async (ctx, next) => {
logger.info(`[DatasetRouter] Checking authorization`);
// Get user from query (delete) or body (post-patch)
const newDatasetCreation = ctx.request.path === '/dataset' && ctx.request.method === 'POST';
const uploadDataset = ctx.request.path.indexOf('upload') >= 0 && ctx.request.method === 'POST';
Function checkSecureDeleteResources
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async checkSecureDeleteResources(id, apiKey) {
logger.info('Checking if it is safe to delete the associated resources (layer, widget) of the dataset');
try {
const layers = await RWAPIMicroservice.requestToMicroservice({
uri: `/v1/dataset/${id}/layer?protected=true`,
Function serialize
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static serialize(data, link = null) {
const result = {};
if (data && Array.isArray(data) && data.length === 0) {
result.data = [];
return result;
Function update
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async update(ctx) {
const id = ctx.params.dataset;
logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
try {
const user = DatasetRouter.getUser(ctx);
Consider simplifying this complex logical expression. Open
Open
if (
search
|| serializeObjToQuery(query).indexOf('concepts[0][0]') >= 0
|| sort.indexOf('most-favorited') >= 0
|| sort.indexOf('most-viewed') >= 0
Function getRelationships
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async getRelationships(datasets, includes, apiKey, query = '', isAdmin = false) {
logger.info(`Getting relationships of datasets`, isAdmin);
datasets.unshift({});
const map = datasets.reduce((acc, val) => {
acc[val._id] = val;
Function notifyAdapterCreate
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async notifyAdapterCreate(ctx, dataset) {
const { connectorType, provider } = dataset;
const clonedDataset = { ...dataset.toObject() };
clonedDataset.id = dataset._id;
Function loadAPI
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const loadAPI = (app, path, pathApi) => {
const routesFiles = fs.readdirSync(path);
let existIndexRouter = false;
routesFiles.forEach((file) => {
const newPath = path ? (`${path}/${file}`) : file;
Function update
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
static async update(ctx) {
const id = ctx.params.dataset;
logger.info(`[DatasetRouter] Updating dataset with id: ${id}`);
try {
const user = DatasetRouter.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 getFields
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async getFields(filePath, provider) {
logger.debug('Obtaining fields');
let fields = null;
try {
switch (provider) {
Function updateEnv
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async updateEnv(datasetId, env, apiKey) {
logger.debug('Updating env of all resources of dataset', datasetId, 'with env ', env);
try {
logger.debug('Updating widgets');
await RWAPIMicroservice.requestToMicroservice({