RocketChat/Rocket.Chat

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

Summary

Maintainability
D
2 days
Test Coverage

File LivechatInquiry.ts has 392 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type {
    ILivechatInquiryRecord,
    IMessage,
    RocketChatRecordDeleted,
    OmnichannelSortingMechanismSettingType,
Severity: Minor
Found in apps/meteor/server/models/raw/LivechatInquiry.ts - About 5 hrs to fix

    LivechatInquiryRaw has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class LivechatInquiryRaw extends BaseRaw<ILivechatInquiryRecord> implements ILivechatInquiryModel {
        constructor(db: Db, trash?: Collection<RocketChatRecordDeleted<ILivechatInquiryRecord>>) {
            super(db, 'livechat_inquiry', trash);
        }
    
    
    Severity: Minor
    Found in apps/meteor/server/models/raw/LivechatInquiry.ts - About 4 hrs to fix

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

          protected modelIndexes(): Array<IndexDescription> {
              return [
                  {
                      key: {
                          rid: 1,
      Severity: Major
      Found in apps/meteor/server/models/raw/LivechatInquiry.ts - About 2 hrs to fix

        Function getCurrentSortedQueueAsync has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            async getCurrentSortedQueueAsync({
                inquiryId,
                department,
                queueSortBy,
            }: {
        Severity: Minor
        Found in apps/meteor/server/models/raw/LivechatInquiry.ts - About 1 hr to fix

          Function findNextAndLock has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              async findNextAndLock(queueSortBy: OmnichannelSortingMechanismSettingType, department?: string): Promise<ILivechatInquiryRecord | null> {
                  const date = new Date();
                  const result = await this.findOneAndUpdate(
                      {
                          status: LivechatInquiryStatus.QUEUED,
          Severity: Minor
          Found in apps/meteor/server/models/raw/LivechatInquiry.ts - About 1 hr to fix

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

                setDefaultAgentById(inquiryId: string, defaultAgent: ILivechatInquiryRecord['defaultAgent']): Promise<UpdateResult> {
                    return this.updateOne(
                        {
                            _id: inquiryId,
                        },
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 2 other locations - About 1 hr to fix
            apps/meteor/server/models/raw/Imports.ts on lines 63..72
            apps/meteor/server/models/raw/Messages.ts on lines 640..642

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

            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

                removeDefaultAgentById(inquiryId: string): Promise<UpdateResult | Document> {
                    return this.updateOne(
                        {
                            _id: inquiryId,
                        },
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatDepartment.ts on lines 266..268

            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

                readyInquiry(inquiryId: string): Promise<UpdateResult> {
                    return this.updateOne(
                        {
                            _id: inquiryId,
                        },
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatInquiry.ts on lines 300..309

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

            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

                openInquiry(inquiryId: string): Promise<UpdateResult> {
                    return this.updateOne(
                        {
                            _id: inquiryId,
                        },
            Severity: Major
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 1 hr to fix
            apps/meteor/server/models/raw/LivechatInquiry.ts on lines 338..349

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

            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 setDepartmentByInquiryId(inquiryId: string, department: string): Promise<ILivechatInquiryRecord | null> {
                    const updated = await this.findOneAndUpdate({ _id: inquiryId }, { $set: { department } }, { returnDocument: 'after' });
                    return updated?.value;
                }
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 55 mins to fix
            apps/meteor/server/models/raw/LivechatInquiry.ts on lines 138..141

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

            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 setLastMessageByRoomId(rid: ILivechatInquiryRecord['rid'], message: IMessage): Promise<ILivechatInquiryRecord | null> {
                    const updated = await this.findOneAndUpdate({ rid }, { $set: { lastMessage: message } }, { returnDocument: 'after' });
                    return updated?.value;
                }
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 55 mins to fix
            apps/meteor/server/models/raw/LivechatInquiry.ts on lines 133..136

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

            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

                }): Promise<(Pick<ILivechatInquiryRecord, '_id' | 'rid' | 'name' | 'ts' | 'status' | 'department'> & { position: number })[]> {
            Severity: Minor
            Found in apps/meteor/server/models/raw/LivechatInquiry.ts and 1 other location - About 50 mins to fix
            packages/model-typings/src/models/ILivechatInquiryModel.ts on lines 28..28

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

            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