RocketChat/Rocket.Chat

View on GitHub
apps/meteor/server/models/raw/LivechatDepartment.ts

Summary

Maintainability
F
3 days
Test Coverage

File LivechatDepartment.ts has 396 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { ILivechatDepartment, RocketChatRecordDeleted } from '@rocket.chat/core-typings';
import type { ILivechatDepartmentModel } from '@rocket.chat/model-typings';
import { LivechatDepartmentAgents, LivechatUnitMonitors } from '@rocket.chat/models';
import { escapeRegExp } from '@rocket.chat/string-helpers';
import type {
Severity: Minor
Found in apps/meteor/server/models/raw/LivechatDepartment.ts - About 5 hrs to fix

    LivechatDepartmentRaw has 38 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class LivechatDepartmentRaw extends BaseRaw<ILivechatDepartment> implements ILivechatDepartmentModel {
        constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<ILivechatDepartment>>) {
            super(db, 'livechat_department', trash);
        }
    
    
    Severity: Minor
    Found in apps/meteor/server/models/raw/LivechatDepartment.ts - About 5 hrs to fix

      Function getBusinessHoursWithDepartmentStatuses has 45 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getBusinessHoursWithDepartmentStatuses(): Promise<
              {
                  _id: string;
                  validDepartments: string[];
                  invalidDepartments: string[];
      Severity: Minor
      Found in apps/meteor/server/models/raw/LivechatDepartment.ts - About 1 hr to fix

        Function modelIndexes has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected modelIndexes(): Array<IndexDescription> {
                return [
                    {
                        key: {
                            name: 1,
        Severity: Minor
        Found in apps/meteor/server/models/raw/LivechatDepartment.ts - About 1 hr to fix

          Function checkIfMonitorIsMonitoringDepartmentById has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              checkIfMonitorIsMonitoringDepartmentById(monitorId: string, departmentId: string): Promise<boolean> {
                  const aggregation = [
                      {
                          $match: {
                              enabled: true,
          Severity: Minor
          Found in apps/meteor/server/models/raw/LivechatDepartment.ts - About 1 hr to fix

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

                findInIds(departmentsIds: string[], options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment> {
                    const query = { _id: { $in: departmentsIds } };
                    return this.find(query, options);
                }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 1 hr to fix
            apps/meteor/ee/server/models/raw/LivechatTag.ts on lines 29..33

            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 3 locations. Consider refactoring.
            Open

                findByBusinessHourId(businessHourId: string, options: FindOptions<ILivechatDepartment>): FindCursor<ILivechatDepartment> {
                    const query = { businessHourId };
                    return this.find(query, options);
                }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 2 other locations - About 1 hr to fix
            apps/meteor/ee/server/models/raw/CannedResponse.ts on lines 82..86
            apps/meteor/server/models/raw/WebdavAccounts.ts on lines 35..38

            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 63.

            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

                updateById(_id: string, update: Partial<ILivechatDepartment>): Promise<Document | UpdateResult> {
                    return this.updateOne({ _id }, update);
                }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatVisitors.ts on lines 289..291

            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 61.

            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 3 locations. Consider refactoring.
            Open

                unarchiveDepartment(_id: string): Promise<Document | UpdateResult> {
                    return this.updateOne({ _id }, { $set: { archived: false } });
                }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 2 other locations - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatDepartmentAgents.ts on lines 368..370
            apps/meteor/server/models/raw/LivechatDepartmentAgents.ts on lines 372..374

            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 60.

            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

                                    invalidDepartments: {
                                        $push: {
                                            $cond: {
                                                if: {
                                                    $or: [{ $eq: ['$enabled', false] }, { $eq: ['$archived', true] }],
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatDepartment.ts on lines 367..384

            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 60.

            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

                                    validDepartments: {
                                        $push: {
                                            $cond: {
                                                if: {
                                                    $or: [
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatDepartment.ts on lines 385..395

            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 60.

            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

                unsetFallbackDepartmentByDepartmentId(departmentId: string): Promise<Document | UpdateResult> {
                    return this.updateMany({ fallbackDepartment: departmentId }, { $unset: { fallbackDepartment: 1 } });
                }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatInquiry.ts on lines 408..417

            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 60.

            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 4 locations. Consider refactoring.
            Open

                    if (_id) {
                        await this.updateOne({ _id }, { $set: record });
                    } else {
                        _id = (await this.insertOne(record)).insertedId;
                    }
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 3 other locations - About 1 hr to fix
            apps/meteor/ee/server/models/raw/LivechatTag.ts on lines 47..51
            apps/meteor/ee/server/models/raw/LivechatUnit.ts on lines 76..80
            apps/meteor/ee/server/models/raw/ServiceLevelAgreements.ts on lines 52..56

            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 58.

            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

                findEnabledWithAgents(projection: FindOptions<ILivechatDepartment>['projection'] = {}): FindCursor<ILivechatDepartment> {
                    const query = {
                        numAgents: { $gt: 0 },
                        enabled: true,
                    };
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 45 mins to fix
            apps/meteor/server/models/raw/LivechatDepartment.ts on lines 292..301

            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 50.

            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

                async findEnabledWithAgentsAndBusinessUnit(
                    _: any,
                    projection: FindOptions<ILivechatDepartment>['projection'] = {},
                ): Promise<FindCursor<ILivechatDepartment>> {
                    const query = {
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 45 mins to fix
            apps/meteor/server/models/raw/LivechatDepartment.ts on lines 284..290

            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 50.

            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

                removeBusinessHourFromDepartmentsByBusinessHourId(businessHourId: string): Promise<Document | UpdateResult> {
                    const query = {
                        businessHourId,
                    };
            
            
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatDepartment.ts and 1 other location - About 40 mins to fix
            apps/meteor/server/models/raw/LivechatRooms.ts on lines 1440..1451

            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