bcgov/common-hosted-email-service

View on GitHub

Showing 117 of 117 total issues

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

class Status extends Model {
  static get tableName () {
    return 'status';
  }

Severity: Major
Found in app/src/services/models/status.js and 1 other location - About 2 hrs to fix
app/src/services/models/queue.js on lines 3..26

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

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

  return Promise.resolve()
    .then(() => knex.schema.alterTable('queue', table => {
      table.dropForeign('messageId');
      table.foreign('messageId').references('messageId').inTable('message').onUpdate('CASCADE').onDelete('CASCADE');
    }))
Severity: Major
Found in app/src/services/migrations/20240229000000_cascade.js and 2 other locations - About 2 hrs to fix
app/src/services/migrations/20240229000000_cascade.js on lines 2..10
app/src/services/migrations/20240229000000_cascade.js on lines 2..14

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

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

  static async onRemoved(job) {
    log.info(`Job ${job.id} removed`, { function: 'onRemoved' });
    await QueueListener.queueService.updateStatus(job, queueState.REMOVED);
    await QueueListener.queueService.updateContent(job);
  }
Severity: Major
Found in app/src/services/queueListener.js and 1 other location - About 1 hr to fix
app/src/services/queueListener.js on lines 36..40

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

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

  static async onCompleted(job) {
    log.info(`Job ${job.id} completed`, { function: 'onCompleted' });
    await QueueListener.queueService.updateStatus(job, queueState.COMPLETED);
    await QueueListener.queueService.updateContent(job);
  }
Severity: Major
Found in app/src/services/queueListener.js and 1 other location - About 1 hr to fix
app/src/services/queueListener.js on lines 102..106

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

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

Function findPromoteMessages has 48 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  async findPromoteMessages(client, messageId, status, tag, transactionId) {
    if (!client) {
      throw new Problem(400, { detail: 'Error finding and promoting messages. Client cannot be null' });
    }

Severity: Minor
Found in app/src/services/chesSvc.js - About 1 hr to fix

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

              if (!models.attachment.encoding(a['encoding'])) {
                errors.push({ value: a['encoding'], message: `Attachments[${i}] invalid value \`encoding\`.` });
                validateSize = false;
              }
    Severity: Major
    Found in app/src/components/validators.js and 2 other locations - About 1 hr to fix
    app/src/components/validators.js on lines 247..250
    app/src/components/validators.js on lines 255..258

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

    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

              if (!models.attachment.filename(a['filename'])) {
                errors.push({ value: a['filename'], message: `Attachments[${i}] invalid value \`filename\`.` });
                validateSize = false;
              }
    Severity: Major
    Found in app/src/components/validators.js and 2 other locations - About 1 hr to fix
    app/src/components/validators.js on lines 251..254
    app/src/components/validators.js on lines 255..258

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

    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

              if (!models.attachment.contentType(a['contentType'])) {
                errors.push({ value: a['contentType'], message: `Attachments[${i}] invalid value \`contentType\`.` });
                validateSize = false;
              }
    Severity: Major
    Found in app/src/components/validators.js and 2 other locations - About 1 hr to fix
    app/src/components/validators.js on lines 247..250
    app/src/components/validators.js on lines 251..254

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

    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

    Function attachments has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      attachments: async (obj, attachmentSizeLimit = DEFAULT_ATTACHMENT_SIZE) => {
        const errors = [];
        if (obj.attachments) {
          if (!Array.isArray(obj.attachments)) {
            errors.push({ value: undefined, message: 'Invalid value `attachments`. Expect an array of attachments.' });
    Severity: Minor
    Found in app/src/components/validators.js - About 1 hr to fix

      Function findCancelMessages has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async findCancelMessages(client, messageId, status, tag, transactionId) {
          if (!client) {
            throw new Problem(400, { detail: 'Error finding and cancelling messages. Client cannot be null' });
          }
      
      
      Severity: Minor
      Found in app/src/services/chesSvc.js - About 1 hr to fix

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

            const status = await chesService.findStatuses(req.authorizedParty, req.query.msgId?.toLowerCase(),
              req.query.status, req.query.tag, req.query.txId?.toLowerCase());
        Severity: Major
        Found in app/src/routes/v1/status.js and 1 other location - About 1 hr to fix
        app/src/routes/v1/cancel.js on lines 10..11

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

        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

            await chesService.findCancelMessages(req.authorizedParty, req.query.msgId?.toLowerCase(),
              req.query.status, req.query.tag, req.query.txId?.toLowerCase());
        Severity: Major
        Found in app/src/routes/v1/cancel.js and 1 other location - About 1 hr to fix
        app/src/routes/v1/status.js on lines 11..12

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

        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

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

        function initializeConnections() {
          // Initialize connections and exit if unsuccessful
          try {
            const tasks = [
              dataConnection.checkAll(),
        Severity: Minor
        Found in app/app.js - About 1 hr to fix

          Function promoteMessage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            async promoteMessage(client, messageId) {
              if (!client || !messageId) {
                throw new Problem(400, { detail: 'Error promoting message. Client and messageId cannot be null' });
              }
          
          
          Severity: Minor
          Found in app/src/services/chesSvc.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 cancelMessage has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

            async cancelMessage(client, messageId) {
              if (!client || !messageId) {
                throw new Problem(400, { detail: 'Error cancelling message. Client and messageId cannot be null' });
              }
          
          
          Severity: Minor
          Found in app/src/services/chesSvc.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

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

              try {
                trx = await Message.startTransaction();
          
                // first query for message, throw not found if client/message not exist...
                await this.readMessage(client, messageId, trx);
          Severity: Major
          Found in app/src/services/dataSvc.js and 2 other locations - About 1 hr to fix
          app/src/services/dataSvc.js on lines 104..127
          app/src/services/dataSvc.js on lines 291..325

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

              try {
                trx = await Message.startTransaction();
          
                // first query for message, throw not found if client/message not exist...
                const msg = await this.readMessage(client, messageId, trx);
          Severity: Major
          Found in app/src/services/dataSvc.js and 2 other locations - About 1 hr to fix
          app/src/services/dataSvc.js on lines 104..127
          app/src/services/dataSvc.js on lines 256..273

          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

          Function contexts has 35 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            contexts: obj => {
              const errors = [];
              if (obj.contexts) {
                if (!Array.isArray(obj.contexts)) {
                  errors.push({ value: undefined, message: 'Invalid value `contexts`. Expect an array of contexts.' });
          Severity: Minor
          Found in app/src/components/validators.js - About 1 hr to fix

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

                try {
                  trx = await Trxn.startTransaction();
                  const transactionId = uuid.v4();
            
                  await Trxn.query(trx).insert({
            Severity: Major
            Found in app/src/services/dataSvc.js and 2 other locations - About 1 hr to fix
            app/src/services/dataSvc.js on lines 256..273
            app/src/services/dataSvc.js on lines 291..325

            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

                  if (integrityList && integrityList.length) {
                    log.error(`Message(s) ${integrityList} inconsistent or corrupted.`, { function: 'findCancelMessages' });
                    throw new Problem(500, {
                      detail: 'Some message(s) are inconsistent or corrupted.',
                      messages: integrityList
            Severity: Major
            Found in app/src/services/chesSvc.js and 1 other location - About 1 hr to fix
            app/src/services/chesSvc.js on lines 245..251

            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

            Severity
            Category
            Status
            Source
            Language