bcgov/common-object-management-service

View on GitHub

Showing 131 of 363 total issues

objectStorageService has 24 functions (exceeds 20 allowed). Consider refactoring.
Open

const objectStorageService = {
  /**
   * @private
   * @function _getS3Client
   * The AWS S3Client used for interacting with S3 compatible storage
Severity: Minor
Found in app/src/services/storage.js - About 2 hrs to fix

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

    exports.up = function (knex) {
      return Promise.resolve()
    
        // create metadata table
        .then(() => knex.schema.createTable('metadata', table => {
    Severity: Major
    Found in app/src/db/migrations/20220627000000_002-metadata-tags.js - About 2 hrs to fix

      Function deleteMetadata has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

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

        Function addMetadata has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

          Function syncMetadata has a Cognitive Complexity of 18 (exceeds 5 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 2 hrs 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 syncObject has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            syncObject: async (path, bucketId, userId = SYSTEM_USER, etrx = undefined) => {
              let trx;
              try {
                trx = etrx ? etrx : await ObjectModel.startTransaction();
          
          
          Severity: Major
          Found in app/src/services/sync.js - About 2 hrs to fix

            Function associateMetadata has a Cognitive Complexity of 17 (exceeds 5 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 2 hrs 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 replaceMetadata has 56 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              Function useInvite has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async useInvite(req, res, next) {
                  const token = addDashesToUuid(req.params.token);
              
                  try {
                    const userId = await userService.getCurrentUserId(getCurrentIdentity(req.currentUser, SYSTEM_USER));
              Severity: Major
              Found in app/src/controllers/invite.js - About 2 hrs to fix

                Function syncTags has 54 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

                  Function searchObjects has 51 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    searchObjects: async (params, etrx = undefined) => {
                      let trx;
                      let response = {};
                      try {
                        trx = etrx ? etrx : await ObjectModel.startTransaction();
                  Severity: Major
                  Found in app/src/services/object.js - About 2 hrs to fix

                    Function errorToProblem has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                    Open

                    function errorToProblem(service, e) {
                      // If already problem type, just return as is
                      if (e instanceof Problem) {
                        return e;
                      } else if (e.response) {
                    Severity: Minor
                    Found in app/src/components/errorToProblem.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 _deriveObjectId has a Cognitive Complexity of 15 (exceeds 5 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

                    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 updateUser has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                      updateUser: async (userId, data, etrx = undefined) => {
                        let trx;
                        try {
                          // Check if any user values have changed
                          const oldUser = await service.readUser(userId);
                    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 up has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    exports.up = function (knex) {
                      return Promise.resolve()
                        // Create bucket tables
                        .then(() => knex.schema.createTable('bucket', table => {
                          table.uuid('bucketId').primary();
                    Severity: Minor
                    Found in app/src/db/migrations/20221014000000_003-multi-bucket.js - About 1 hr to fix

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

                        async processNextJob() {
                          let job;
                      
                          try {
                            const response = await objectQueueService.dequeue();
                      Severity: Minor
                      Found in app/src/components/queueManager.js - About 1 hr to fix

                        Function createBucketChild has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          async createBucketChild(req, res, next) {
                            try {
                              // Get Parent bucket data
                              const parentBucketId = addDashesToUuid(req.params.bucketId);
                              const parentBucket = await bucketService.read(parentBucketId);
                        Severity: Minor
                        Found in app/src/controllers/bucket.js - About 1 hr to fix

                          Function Encrypt has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          const Encrypt = opts => {
                            // Provide good default options if possible.
                            const options = Object.assign(
                              {
                                fields: []
                          Severity: Minor
                          Found in app/src/db/models/mixins/encrypt.js - About 1 hr to fix

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

                              static get modifiers() {
                                return {
                                  filterUserId(query, value) {
                                    filterOneOrMany(query, value, 'userId');
                                  },
                            Severity: Minor
                            Found in app/src/db/models/tables/user.js - About 1 hr to fix

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

                                async addTags(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
                                Severity
                                Category
                                Status
                                Source
                                Language