Lambda-School-Labs/shopping-cart-be

View on GitHub

Showing 87 of 87 total issues

Function addCart has 65 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 recover has 37 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

            Function submitCart has 34 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 createStore has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              async function createStore(req, res) {
                  const { businessName } = req.body;
                  const { sub: sellerId } = req.decodedToken;
              
                  try {
              Severity: Minor
              Found in controllers/seller/createStore.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 validateProductInput has 31 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 { productName, description, price, stock } = data;
                      productName = productName || '';
                  Severity: Minor
                  Found in middleware/validateProductData.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 register has 29 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 editProduct has 28 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 editStore has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          async function editStore(req, res) {
                              const { sub } = req.decodedToken;
                              const { businessName } = req.body;
                          
                              //   find seller / store
                          Severity: Minor
                          Found in controllers/seller/editStore.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 { productName, description, price, stock } = data;
                                productName = productName || '';
                            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 updatePhone has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

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

                              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

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

                              async function updatePhone(req, res) {
                                  const { sub } = req.decodedToken;
                                  const { errors, isValid } = req.body;
                              
                                  if (!isValid) {
                              Severity: Minor
                              Found in controllers/seller/updateSeller.js - About 35 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 7 (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.businessName = !isEmpty(data.businessName) ? data.businessName : '';
                              Severity: Minor
                              Found in middleware/validateEditInput.js - About 35 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