betagouv/service-national-universel

View on GitHub
api/src/controllers/elasticsearch/utils.js

Summary

Maintainability
A
1 hr
Test Coverage

Function aggsSubQuery has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Wontfix

function aggsSubQuery(keys, aggsSearchQuery, queryFilters, contextFilters, customQueries) {
  let aggs = {};
  for (const key of keys) {
    const keyWithoutKeyword = key.replace(".keyword", "");
    let filter = unsafeStrucuredClone({ bool: { must: [], filter: contextFilters } });
Severity: Minor
Found in api/src/controllers/elasticsearch/utils.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 buildMissionContext has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

async function buildMissionContext(user) {
  const contextFilters = [];

  // A young can only see validated missions.
  if (isYoung(user)) contextFilters.push({ term: { "status.keyword": "VALIDATED" } });
Severity: Minor
Found in api/src/controllers/elasticsearch/utils.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 aggsSubQuery has 5 arguments (exceeds 4 allowed). Consider refactoring.
Wontfix

function aggsSubQuery(keys, aggsSearchQuery, queryFilters, contextFilters, customQueries) {
Severity: Minor
Found in api/src/controllers/elasticsearch/utils.js - About 35 mins to fix

    Function buildApplicationContext has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    async function buildApplicationContext(user) {
      const contextFilters = [];
    
      if (!canSearchInElasticSearch(user, "application")) return { applicationContextError: { status: 403, body: { ok: false, code: ERRORS.OPERATION_UNAUTHORIZED } } };
    
    
    Severity: Minor
    Found in api/src/controllers/elasticsearch/utils.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 buildRequestBody has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Wontfix

    function buildRequestBody({ searchFields, filterFields, queryFilters, page, sort, contextFilters, customQueries, size = 10 }) {
      // We always need a fresh query to avoid side effects.
      const getMainQuery = () => unsafeStrucuredClone({ bool: { must: [{ match_all: {} }], filter: contextFilters } });
      // Search query
      const search = (queryFilters.searchbar || []).filter((e) => e.trim()).length ? searchSubQuery(queryFilters.searchbar, searchFields) : null;
    Severity: Minor
    Found in api/src/controllers/elasticsearch/utils.js - About 25 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

    There are no issues that match your filters.

    Category
    Status