bcgov/common-hosted-email-service

View on GitHub

Showing 34 of 117 total issues

File validators.js has 407 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const bytes = require('bytes');
const fs = require('fs');
const tmp = require('tmp');
const validator = require('validator');

Severity: Minor
Found in app/src/components/validators.js - About 5 hrs to fix

    File chesSvc.js has 286 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /**
     * @module ChesService
     *
     * Create a business service for CHES.
     * Provide a wrapper around business functions that use multiple services.
    Severity: Minor
    Found in app/src/services/chesSvc.js - About 2 hrs to fix

      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

        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

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

              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

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

                export default function (data) {
                  console.log(`VU: ${__VU}  -  ITER: ${__ITER}`);
                  console.debug('Running Tests');
                  console.debug(`Data from setup: ${JSON.stringify(data)}`);
                  if (!data.token) {
                Severity: Minor
                Found in load-tests/script.js - About 1 hr to fix

                  Function up has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  exports.up = function (knex) {
                  
                    const statusTable = (table) => {
                      table.uuid('messageId').references('messageId').inTable('message').notNullable().index();
                      table.string('status').notNullable().defaultTo('accepted');
                  Severity: Minor
                  Found in app/src/services/migrations/20191016164716_init.js - About 1 hr to fix

                    Function relationMappings has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static relationMappings () {
                        const Queue = require('./queue');
                        const Status = require('./status');
                        const Trxn = require('./trxn');
                        return {
                    Severity: Minor
                    Found in app/src/services/models/message.js - About 1 hr to fix

                      Function sendEmailMerge has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        async sendEmailMerge(client, template, ethereal = false) {
                          if (!template) {
                            throw new Problem(400, { detail: 'Error sending email merge. Email templates/contexts cannot be null' });
                          }
                          if (!ethereal && !client) {
                      Severity: Minor
                      Found in app/src/services/chesSvc.js - About 1 hr to fix

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

                          async updateStatus(client, messageId, status, description) {
                            let trx;
                            try {
                              trx = await Message.startTransaction();
                        
                        
                        Severity: Minor
                        Found in app/src/services/dataSvc.js - About 1 hr to fix

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

                          export function setup() {
                            console.log(`Email url: ${emailUrl}`);
                            console.log(`SSO url: ${oidcUrl}`);
                            console.debug('Getting Token');
                            // Check a secret was supplied or nothing will work
                          Severity: Minor
                          Found in load-tests/script.js - About 1 hr to fix

                            Function promoteMessage has 27 lines of code (exceeds 25 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

                              Function cancelMessage has 27 lines of code (exceeds 25 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

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

                                const _createClient = () => {
                                  let redis;
                                
                                  const redisOpts = {
                                    enableReadyCheck: false, // Bull forcibly assumes Redis is ready if it has connected to it
                                Severity: Minor
                                Found in app/src/services/queueConn.js - About 1 hr to fix

                                  Function close has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    close(cb = undefined) {
                                      if (this.queue) {
                                        try {
                                          this.queue.whenCurrentJobsFinished().then(() => {
                                            this.queue.close().then(() => {
                                  Severity: Minor
                                  Found in app/src/services/queueConn.js - About 55 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

                                  Function updateStatus has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    async updateStatus(client, messageId, status, description) {
                                      let trx;
                                      try {
                                        trx = await Message.startTransaction();
                                  
                                  
                                  Severity: Minor
                                  Found in app/src/services/dataSvc.js - About 55 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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language