Asymmetrik/node-rest-starter

View on GitHub
src/app/core/teams/teams.service.ts

Summary

Maintainability
F
5 days
Test Coverage

File teams.service.ts has 648 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash';
import mongoose, { FilterQuery, PopulateOptions, Types } from 'mongoose';

import {
    TeamRoleImplicit,
Severity: Major
Found in src/app/core/teams/teams.service.ts - About 1 day to fix

    Function updateMemberFilter has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

        updateMemberFilter(query: FilterQuery<UserDocument>, team: TeamDocument) {
            // Extract member types and roles for filtering
            const types = query.$and?.find((filter) => filter.type)?.type.$in ?? [];
            const roles: TeamRoles[] =
                query.$and?.find((filter) => filter.role)?.role.$in ?? [];
    Severity: Minor
    Found in src/app/core/teams/teams.service.ts - About 4 hrs 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

    TeamsService has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class TeamsService {
        constructor(
            private model: TeamModel,
            private userModel: UserModel
        ) {}
    Severity: Minor
    Found in src/app/core/teams/teams.service.ts - About 4 hrs to fix

      Function getImplicitTeamIds has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async getImplicitTeamIds(
              user: IUser,
              ...roles: TeamRoles[]
          ): Promise<Types.ObjectId[]> {
              // Validate the user input
      Severity: Major
      Found in src/app/core/teams/teams.service.ts - About 2 hrs to fix

        Function updateMemberFilter has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            updateMemberFilter(query: FilterQuery<UserDocument>, team: TeamDocument) {
                // Extract member types and roles for filtering
                const types = query.$and?.find((filter) => filter.type)?.type.$in ?? [];
                const roles: TeamRoles[] =
                    query.$and?.find((filter) => filter.role)?.role.$in ?? [];
        Severity: Major
        Found in src/app/core/teams/teams.service.ts - About 2 hrs to fix

          Function search has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async search(
                  queryParams = {},
                  query: FilterQuery<TeamDocument> = {},
                  search = '',
                  user: UserDocument
          Severity: Minor
          Found in src/app/core/teams/teams.service.ts - About 1 hr to fix

            Function getImplicitTeamIds has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                async getImplicitTeamIds(
                    user: IUser,
                    ...roles: TeamRoles[]
                ): Promise<Types.ObjectId[]> {
                    // Validate the user input
            Severity: Minor
            Found in src/app/core/teams/teams.service.ts - 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 requestNewTeam has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async requestNewTeam(
                    org: string,
                    aoi: string,
                    description: string,
                    requester: UserDocument,
            Severity: Minor
            Found in src/app/core/teams/teams.service.ts - About 1 hr to fix

              Function updateTeams has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async updateTeams(user: IUser) {
                      const strategy = config.get('teams.implicitMembers.strategy');
                      const nestedTeamsEnabled = config.get<boolean>('teams.nestedTeams');
              
                      if (strategy === 'disabled' && !nestedTeamsEnabled) {
              Severity: Minor
              Found in src/app/core/teams/teams.service.ts - About 1 hr to fix

                Avoid deeply nested control flow statements.
                Open

                                if (implicitFilter) {
                                    query.$or.push(implicitFilter);
                                }
                Severity: Major
                Found in src/app/core/teams/teams.service.ts - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                  if (implicitFilter) {
                                      query.$or.push(implicitFilter);
                                  }
                  Severity: Major
                  Found in src/app/core/teams/teams.service.ts - About 45 mins to fix

                    Function search has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        async search(
                            queryParams = {},
                            query: FilterQuery<TeamDocument> = {},
                            search = '',
                            user: UserDocument
                    Severity: Minor
                    Found in src/app/core/teams/teams.service.ts - 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

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            if (strategy === 'teams' && (user.externalGroups?.length ?? 0) > 0) {
                                query.$and.push(
                                    {
                                        requiresExternalTeams: { $exists: true }
                                    },
                    Severity: Major
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 3 hrs to fix
                    src/app/core/teams/teams.service.ts on lines 717..734

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 114.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            if (strategy === 'roles' && (user.externalRoles?.length ?? 0) > 0) {
                                query.$and.push(
                                    {
                                        requiresExternalRoles: { $exists: true }
                                    },
                    Severity: Major
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 3 hrs to fix
                    src/app/core/teams/teams.service.ts on lines 735..752

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 114.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            if (
                                implicitTeamStrategy === 'teams' &&
                                team.requiresExternalTeams?.length > 0
                            ) {
                                return {
                    Severity: Major
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 1 hr to fix
                    src/app/core/teams/teams.service.ts on lines 408..418

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 71.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                            if (
                                implicitTeamStrategy === 'roles' &&
                                team.requiresExternalRoles?.length > 0
                            ) {
                                return {
                    Severity: Major
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 1 hr to fix
                    src/app/core/teams/teams.service.ts on lines 419..429

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 71.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                                query.$or.push({
                                    teams: { $elemMatch: { _id: team._id, role: { $in: roles } } }
                                });
                    Severity: Minor
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 40 mins to fix
                    src/app/core/teams/teams.service.ts on lines 462..464

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                                    query.$or.push({
                                        teams: { $elemMatch: { _id: team._id, role: { $in: roles } } }
                                    });
                    Severity: Minor
                    Found in src/app/core/teams/teams.service.ts and 1 other location - About 40 mins to fix
                    src/app/core/teams/teams.service.ts on lines 483..485

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 48.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status