Giter VIP home page Giter VIP logo

ecommerce-clean-arch's Introduction

JOB-STATUS Coverage Status

Welcome to the Clean Architecture E-Commerce Project

This repository is my personal implementation of the E-Commerce Project studied at Clean Code & Clean Architecture Course.

Objective

The main goal here is to create a simple e-commerce implementation using SOLID principles,Object Oriented Programming, Refactoring Techniques", Clean Architecture, Domain Driven Design, Test Driven Development and some Design Patterns.


Applied Practices

Good Practices

Code Quality

  • Eslint
    • Airbnb Typescript
    • Personal Rules
  • Prettier
    • Default

Tests

  • Jest
    • Mapped Paths
    • Ts-Jest
  • Test Patterns
    • Mocks
    • Spies
    • System Under Test (SUT)

CI/CD

  • GitHub Actions
    • Jobs:
      • Test
      • Eslint
      • Coveralls

Challenges

CPF Validation Refactor

Function to Refactor:

  • Obs: The results are accessible in the refactor/cpf-challenge branch into the SRC folder
    • "FirstRefactor.ts" is the first result using functions
    • "CpfValidation.ts" is the last result using Typescript with Classes and Interfaces
// @ts-nocheck
export function validate(str) {
    if (str !== null) {
        if (str !== undefined) {
            if (str.length >= 11 || str.length <= 14) {
                str = str
                    .replace('.', '')
                    .replace('.', '')
                    .replace('-', '')
                    .replace(' ', '')

                if (!str.split('').every((c) => c === str[0])) {
                    try {
                        let d1
                        let d2
                        let dg1
                        let dg2
                        let rest
                        let digito
                        let nDigResult
                        d1 = d2 = 0
                        dg1 = dg2 = rest = 0

                        for (
                            let nCount = 1;
                            nCount < str.length - 1;
                            nCount++
                        ) {
                            // if (isNaN(parseInt(str.substring(nCount -1, nCount)))) {
                            // 	return false;
                            // } else {

                            digito = parseInt(str.substring(nCount - 1, nCount))
                            d1 += (11 - nCount) * digito

                            d2 += (12 - nCount) * digito
                            // }
                        }

                        rest = d1 % 11

                        dg1 = rest < 2 ? (dg1 = 0) : 11 - rest
                        d2 += 2 * dg1
                        rest = d2 % 11
                        if (rest < 2) {
                            dg2 = 0
                        } else {
                            dg2 = 11 - rest
                        }

                        const nDigVerific = str.substring(
                            str.length - 2,
                            str.length
                        )
                        nDigResult = `${dg1}${dg2}`
                        return nDigVerific == nDigResult
                    } catch (e) {
                        console.error(`Erro !${e}`)

                        return false
                    }
                } else return false
            } else return false
        }
    } else return false
}

ecommerce-clean-arch's People

Contributors

lucassgomide avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.