RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/livechat/server/api/v1/room.ts

Summary

Maintainability
D
2 days
Test Coverage

File room.ts has 359 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Omnichannel } from '@rocket.chat/core-services';
import type { ILivechatAgent, IUser, SelectedAgent, TransferByData } from '@rocket.chat/core-typings';
import { isOmnichannelRoom, OmnichannelSourceType } from '@rocket.chat/core-typings';
import { LivechatVisitors, Users, LivechatRooms, Messages } from '@rocket.chat/models';
import {
Severity: Minor
Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 4 hrs to fix

    Function post has 54 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            async post() {
                const { rid, token } = this.bodyParams;
    
                const visitor = await findGuest(token);
                if (!visitor) {
    Severity: Major
    Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 2 hrs to fix

      Function get has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              async get() {
                  // I'll temporary use check for validation, as validateParams doesnt support what's being done here
                  const extraCheckParams = await onCheckRoomParams({
                      token: String,
                      rid: Match.Maybe(String),
      Severity: Minor
      Found in apps/meteor/app/livechat/server/api/v1/room.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 get has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              async get() {
                  // I'll temporary use check for validation, as validateParams doesnt support what's being done here
                  const extraCheckParams = await onCheckRoomParams({
                      token: String,
                      rid: Match.Maybe(String),
      Severity: Minor
      Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 1 hr to fix

        Function post has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                async post() {
                    const transferData = this.bodyParams as typeof this.bodyParams & {
                        transferredBy: TransferByData;
                        transferredTo?: { _id: string; username?: string; name?: string };
                    };
        Severity: Minor
        Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 1 hr to fix

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

                  async post() {
                      const { rid, token } = this.bodyParams;
          
                      const visitor = await findGuest(token);
                      if (!visitor) {
          Severity: Minor
          Found in apps/meteor/app/livechat/server/api/v1/room.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 post has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                  async post() {
                      const { rid, token, data } = this.bodyParams;
          
                      const visitor = await findGuest(token);
                      if (!visitor) {
          Severity: Minor
          Found in apps/meteor/app/livechat/server/api/v1/room.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 post has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  async post() {
                      const { rid, token, data } = this.bodyParams;
          
                      const visitor = await findGuest(token);
                      if (!visitor) {
          Severity: Minor
          Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 1 hr to fix

            Function post has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                    async post() {
                        const transferData = this.bodyParams as typeof this.bodyParams & {
                            transferredBy: TransferByData;
                            transferredTo?: { _id: string; username?: string; name?: string };
                        };
            Severity: Minor
            Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 45 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

            Consider simplifying this complex logical expression.
            Open

                            if (
                                !rcSettings.get<boolean>('Livechat_enable_transcript') &&
                                servingAgent?.settings?.preferences?.omnichannelTranscriptEmail &&
                                visitor.visitorEmails?.length &&
                                visitor.visitorEmails?.[0]?.address
            Severity: Major
            Found in apps/meteor/app/livechat/server/api/v1/room.ts - About 40 mins to fix

              There are no issues that match your filters.

              Category
              Status