bcgov/common-object-management-service

View on GitHub

Showing 131 of 360 total issues

Function currentUser has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const currentUser = async (req, res, next) => {
  const authorization = req.get('Authorization');
  const currentUser = {
    authType: AuthType.NONE
  };
Severity: Minor
Found in app/src/middleware/authentication.js - About 1 hr to fix

    Function createUser has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      createUser: async (data, etrx = undefined) => {
        let trx;
        try {
          let response;
          trx = etrx ? etrx : await User.startTransaction();
    Severity: Minor
    Found in app/src/services/user.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 deleteTags has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async deleteTags(req, res, next) {
        try {
          const bucketId = req.currentObject?.bucketId;
          const objId = addDashesToUuid(req.params.objectId);
          const objPath = req.currentObject?.path;
    Severity: Minor
    Found in app/src/controllers/object.js - About 1 hr to fix

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

        syncMetadata: async (version, path, bucketId = undefined, userId = SYSTEM_USER, etrx = undefined) => {
          let trx;
          try {
            trx = etrx ? etrx : await Version.startTransaction();
            let response = [];
      Severity: Minor
      Found in app/src/services/sync.js - About 1 hr to fix

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

          copy: async (sourceVersionId, targetVersionId, objectId, targetEtag, targetLastModified,
            userId = SYSTEM_USER, etrx = undefined) => {
            let trx;
            try {
              trx = etrx ? etrx : await Version.startTransaction();
        Severity: Minor
        Found in app/src/services/version.js - About 1 hr to fix

          Function associateMetadata has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            associateMetadata: async (versionId, metadata, currentUserId = SYSTEM_USER, etrx = undefined) => {
              let trx;
              try {
                trx = etrx ? etrx : await Metadata.startTransaction();
                let response = [];
          Severity: Minor
          Found in app/src/services/metadata.js - About 1 hr to fix

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

              static get relationMappings() {
                const Bucket = require('./bucket');
                const ObjectPermission = require('./objectPermission');
                const BucketPermission = require('./bucketPermission');
                const Version = require('./version');
            Severity: Minor
            Found in app/src/db/models/tables/objectModel.js - About 1 hr to fix

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

                fetchMetadataForVersion: async (params, etrx = undefined) => {
                  let trx;
                  try {
                    trx = etrx ? etrx : await Metadata.startTransaction();
              
              
              Severity: Minor
              Found in app/src/services/metadata.js - About 1 hr to fix

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

                  static get relationMappings() {
                    const ObjectModel = require('./objectModel');
                    const Metadata = require('./metadata');
                    const Tag = require('./tag');
                
                
                Severity: Minor
                Found in app/src/db/models/tables/version.js - About 1 hr to fix

                  Function down has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  exports.down = function (knex) {
                    return Promise.resolve()
                      // re-add columns originalName and mimeType to object table
                      .then(() => knex.schema.alterTable('object', table => {
                        table.string('originalName', 255);
                  Severity: Minor
                  Found in app/src/db/migrations/20220516000000_001-version.js - About 1 hr to fix

                    Function fetchTagsForVersion has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      fetchTagsForVersion: async (params, etrx = undefined) => {
                        let trx;
                        try {
                          trx = etrx ? etrx : await Tag.startTransaction();
                    
                    
                    Severity: Minor
                    Found in app/src/services/tag.js - About 1 hr to fix

                      Function deleteObject has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        async deleteObject(req, res, next) {
                          try {
                            const objId = addDashesToUuid(req.params.objectId);
                            const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
                      
                      
                      Severity: Minor
                      Found in app/src/controllers/object.js - About 1 hr to fix

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

                          checkGrantPermissions: async (data, etrx = undefined) => {
                            let trx;
                            try {
                              trx = etrx ? etrx : await Bucket.startTransaction();
                        
                        
                        Severity: Minor
                        Found in app/src/services/bucket.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 readObject has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          async readObject(req, res, next) {
                            try {
                              const objId = addDashesToUuid(req.params.objectId);
                        
                              // target S3 version
                        Severity: Minor
                        Found in app/src/controllers/object.js - About 1 hr to fix

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

                            createUser: async (data, etrx = undefined) => {
                              let trx;
                              try {
                                let response;
                                trx = etrx ? etrx : await User.startTransaction();
                          Severity: Minor
                          Found in app/src/services/user.js - About 1 hr to fix

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

                              _deriveObjectId: async (s3Object, path, bucketId) => {
                                let objId = uuidv4();
                            
                                if (typeof s3Object === 'object') { // If regular S3 Object
                                  const TagSet = await storageService.getObjectTagging({ filePath: path, bucketId: bucketId })
                            Severity: Minor
                            Found in app/src/services/sync.js - About 1 hr to fix

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

                              const currentUpload = (strict = false) => {
                                return (req, _res, next) => {
                                  // Check Content-Length Header
                                  const contentLength = parseInt(req.get('Content-Length'));
                                  // TODO: Figure out what's killing and returning a 400 in response stack
                              Severity: Minor
                              Found in app/src/middleware/upload.js - About 1 hr to fix

                                Function modifiers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  static get modifiers() {
                                    return {
                                      filterKey(query, value) {
                                        const subqueries = [];
                                        if (value.metadata && Object.keys(value.metadata).length) {
                                Severity: Minor
                                Found in app/src/db/models/tables/metadata.js - About 1 hr to fix

                                  Function modifiers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                    static get modifiers() {
                                      return {
                                        filterKey(query, value) {
                                          const subqueries = [];
                                          if (value.tag && Object.keys(value.tag).length) {
                                  Severity: Minor
                                  Found in app/src/db/models/tables/tag.js - About 1 hr to fix

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

                                    const hasPermission = (permission) => {
                                      return async (req, _res, next) => {
                                        const authMode = getAppAuthMode();
                                        const authType = req.currentUser ? req.currentUser.authType : undefined;
                                    
                                    
                                    Severity: Minor
                                    Found in app/src/middleware/authorization.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

                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language