Easybuoy/storemanager

View on GitHub

Showing 17 of 17 total issues

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

  static createSale(req, res) {
    const processSale = (order) => {
      let isMoreThanStock = false;
      let isNotProductAvailable = false;
      let totalSalesAmount = 0;
Severity: Major
Found in server/controllers/saleController.js - About 2 hrs to fix

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

    const validateSignupInput = (input) => {
      const errors = {};
      const data = input;
      data.name = !isEmpty(data.name) ? data.name : '';
      data.email = !isEmpty(data.email) ? data.email : '';
    Severity: Minor
    Found in server/validation/users.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 signup has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      static signup(req, res) {
        const { errors, isValid } = usersValidation.validateSignupInput(req.body);
    
        // Check validation
        if (!isValid) {
    Severity: Minor
    Found in server/controllers/userController.js - About 1 hr to fix

      Function validateSignupInput has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const validateSignupInput = (input) => {
        const errors = {};
        const data = input;
        data.name = !isEmpty(data.name) ? data.name : '';
        data.email = !isEmpty(data.email) ? data.email : '';
      Severity: Minor
      Found in server/validation/users.js - About 1 hr to fix

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

          static login(req, res) {
            const { errors, isValid } = usersValidation.validateLoginInput(req.body);
        
            // Check validation
            if (!isValid) {
        Severity: Minor
        Found in server/controllers/userController.js - About 1 hr to fix

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

              const processSale = (order) => {
                let isMoreThanStock = false;
                let isNotProductAvailable = false;
                let totalSalesAmount = 0;
                order.map((ordertobeprocessed) => {
          Severity: Minor
          Found in server/controllers/saleController.js - About 1 hr to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            const openSlideMenu = () => {
              document.getElementById('side-menu').style.width = '250px';
              document.getElementById('main').style.marginLeft = '250px';
            };
            Severity: Major
            Found in UI/js/main.js and 1 other location - About 1 hr to fix
            UI/js/main.js on lines 9..12

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 58.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

            const closeSlideMenu = () =>{
              document.getElementById('side-menu').style.width = '0';
              document.getElementById('main').style.marginLeft = '0';
            };
            Severity: Major
            Found in UI/js/main.js and 1 other location - About 1 hr to fix
            UI/js/main.js on lines 3..6

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 58.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

            const addtocart = (nameofproduct, amountofproduct) => {
              const quantity = document.getElementById('number').value;
              let product = {};
              let data = [];
            
            
            Severity: Minor
            Found in UI/js/main.js - About 1 hr to fix

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

                static createProduct(req, res) {
                  const { errors, isValid } = productsValidation.validateProductInput(req.body);
                  // Check validation
                  if (!isValid) {
                    return res.status(400).json(errors);
              Severity: Minor
              Found in server/controllers/productController.js - About 1 hr to fix

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                  static isStoreAttendant(req, res, next) {
                    if (req.user.type !== 3) {
                      return res.status(401).json({ message: 'Unauthorized' });
                    }
                    next();
                Severity: Minor
                Found in server/middleware/authenticate.js and 1 other location - About 55 mins to fix
                server/middleware/authenticate.js on lines 23..28

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                  static isAdmin(req, res, next) {
                    if (req.user.type !== 1) {
                      return res.status(401).json({ message: 'Unauthorized' });
                    }
                    next();
                Severity: Minor
                Found in server/middleware/authenticate.js and 1 other location - About 55 mins to fix
                server/middleware/authenticate.js on lines 40..45

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 54.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

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

                  static getSaleById(req, res) {
                    // check if user making the request is the Store Owner / Admin
                
                    if (!Number(req.user.type) === 1 || !Number(req.user.type) === 3) {
                      return res.status(401).json({ message: 'Unauthorized' });
                Severity: Minor
                Found in server/controllers/saleController.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 validateProductInput has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                const validateProductInput = (input) => {
                  const errors = {};
                  const data = input;
                  data.name = !isEmpty(data.name) ? data.name : '';
                  data.description = !isEmpty(data.description) ? data.description : '';
                Severity: Minor
                Found in server/validation/products.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

                Consider simplifying this complex logical expression.
                Open

                  if (value === undefined || value === null || (typeof value === 'object' && Object.keys(value).length === 0) || (typeof value === 'string' && value.trim().length === 0)) {
                    return true;
                  }
                Severity: Major
                Found in server/validation/isEmpty.js - About 40 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return res.json({ message: 'Unable to delete product.' });
                  Severity: Major
                  Found in server/controllers/productController.js - About 30 mins to fix

                    Function createSale has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      static createSale(req, res) {
                        const processSale = (order) => {
                          let isMoreThanStock = false;
                          let isNotProductAvailable = false;
                          let totalSalesAmount = 0;
                    Severity: Minor
                    Found in server/controllers/saleController.js - About 25 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