LABS-EU3/shopping_cart_backend

View on GitHub

Showing 30 of 79 total issues

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

async function addCart (req, res) {
  const { errors, isValid } = validateCartInput(req.body)
  const { errorEmail, isValidEmail } = validateEmail(req.body)
  if (!isValid) {
    return res.status(400).json(errors)
Severity: Major
Found in controllers/cart/addCart.js - About 2 hrs to fix

    Function getSalesHistory has 56 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    async function getSalesHistory (req, res) {
      try {
        const seller = req.decodedToken.sub
        const store = await Store.findOne({ seller })
    
    
    Severity: Major
    Found in controllers/seller/getSalesHistory.js - About 2 hrs to fix

      Function authenticate has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

      OAuth2Strategy.prototype.authenticate = function (req, options) {
        options = options || {}
        var self = this
      
        if (req.query && req.query.error) {
      Severity: Minor
      Found in authentication/stripeStrategy.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 authenticate has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      OAuth2Strategy.prototype.authenticate = function (req, options) {
        options = options || {}
        var self = this
      
        if (req.query && req.query.error) {
      Severity: Minor
      Found in authentication/stripeStrategy.js - About 1 hr to fix

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

        async function getCart (req, res) {
          try {
            const cartId = req.params.cart_id
            const cart = await Cart.findById({ _id: cartId })
            if (!cart) {
        Severity: Minor
        Found in controllers/cart/getCart.js - About 1 hr to fix

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

          async function editStore (req, res) {
            const { sub } = req.decodedToken
            const { errors, isValid } = validateEditInput(req.body)
            const { ownerName, currency, imageUrl, storeName, address } = req.body
          
          
          Severity: Minor
          Found in controllers/seller/editStore.js - About 1 hr to fix

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

            async function recover (req, res) {
              try {
                const { errors, isValid } = validateRecoverPhone(req.body)
            
                if (!isValid) {
            Severity: Minor
            Found in controllers/seller/passwordReset.js - About 1 hr to fix

              Consider simplifying this complex logical expression.
              Open

                if (req.query && req.query.code) {
                  var code = req.query.code
              
                  // NOTE: The module oauth (0.9.5), which is a dependency, automatically adds
                  //       a 'type=web_server' parameter to the percent-encoded data sent in
              Severity: Critical
              Found in authentication/stripeStrategy.js - About 1 hr to fix

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

                async function createStore (req, res) {
                  const { storeName } = req.body
                  const { sub: sellerId } = req.decodedToken
                
                  const { errors, isValid } = validateCreateStoreInput(req.body)
                Severity: Minor
                Found in controllers/seller/createStore.js - About 1 hr to fix

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

                  async function updatePhone (req, res) {
                    const { sub } = req.decodedToken
                    const { errors, isValid } = validatePhone(req.body)
                  
                    if (!isValid) {
                  Severity: Minor
                  Found in controllers/seller/updateSeller.js - About 1 hr to fix

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

                    async function resetPassword (req, res) {
                      try {
                        const { errors, isValid } = validatePasswordResetInput(req.body)
                        if (!isValid) {
                          return res.status(400).json(errors)
                    Severity: Minor
                    Found in controllers/seller/passwordReset.js - About 1 hr to fix

                      Function submitCart has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      async function submitCart (req, res) {
                        const { errors, isValid } = validateCartInput(req.body)
                        if (!isValid) {
                          return res.status(400).json(errors)
                        }
                      Severity: Minor
                      Found in controllers/cart/submitCart.js - About 1 hr to fix

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

                        function validateProductInput (data) {
                          const errors = {}
                          // Convert empty fields to an empty string so we can use validator functions
                          let { name, description, price, stock } = data
                          name = name || ''
                        Severity: Minor
                        Found in middleware/validateProductData.js - About 1 hr to fix

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

                          function register (req, res) {
                            const { errors, isValid } = validateRegisterInput(req.body)
                            if (!isValid) {
                              return res.status(400).json(errors)
                            }
                          Severity: Minor
                          Found in controllers/seller/register.js - About 1 hr to fix

                            Function validateProductInput has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                            function validateProductInput (data) {
                              const errors = {}
                              // Convert empty fields to an empty string so we can use validator functions
                              let { name, description, price, stock } = data
                              name = name || ''
                            Severity: Minor
                            Found in middleware/validateProductData.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 editProduct has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            async function editProduct (req, res) {
                              const { errors, isValid } = validateProductData(req.body)
                              const productId = req.params.product_id
                            
                              if (!isValid) {
                            Severity: Minor
                            Found in controllers/product/editProduct.js - About 1 hr to fix

                              Function validateCartInput has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                              function validateCartInput (data) {
                                const errors = {}
                                // Convert empty fields to an empty string so we can use validator functions
                                let { agreedPrice, total } = data
                              
                              
                              Severity: Minor
                              Found in middleware/validateCartData.js - About 45 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 validateCreateStoreInput has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                              function validateCreateStoreInput (data) {
                                const errors = {}
                                // Convert empty fields to an empty string so we can use validator functions
                                data.ownerName = !isEmpty(data.ownerName) ? data.ownerName : ''
                                data.currency = !isEmpty(data.currency) ? data.currency : ''
                              Severity: Minor
                              Found in middleware/validateCreateStoreData.js - About 45 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 validateEditInput has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                              function validateEditInput (data) {
                                const errors = {}
                              
                                // Convert empty fields to an empty string so we can use validator functions
                                data.ownerName = !isEmpty(data.ownerName) ? data.ownerName : ''
                              Severity: Minor
                              Found in middleware/validateEditInput.js - About 45 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 getOneStore has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                              Open

                              async function getOneStore (req, res) {
                                try {
                                  let seller = ''
                                  const sellerId = req.decodedToken ? req.decodedToken.sub : null
                                  const store_id = req.params.store_id ? req.params.store_id : null
                              Severity: Minor
                              Found in controllers/seller/getStore.js - About 45 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