Simple and secure payment service between people. Side project made to get hands dirty in back-end development with node and typescript.
Node@20.0.9
Typescript@5.3.3
Vitest@1.2.1
Using docker:
- Build the Docker Image: After creating the Dockerfile, you can build the Docker image using the following command:
docker build -t simply-paid .
This command tells Docker to build an image using the Dockerfile in the current directory and tag (-t) the image with the name "simply-paid".
- Run the Docker Container: Once the image has been built, you can run it as a container with the following command:
docker run -p 3000:3000 -d simply-paid
This command tells Docker to run a container from the "simply-paid" image, map port 3000 of the container to port 3000 of the host machine, and run the container in detached mode (-d).
First of all, after a slow and patient reading through the requirements, I got to understand what is the purpose of the project. Then I started some sketches to plan what I had to do and write some tests about the use cases.
The Result
class in TypeScript is a design pattern used to handle operations that can either succeed or fail. It encapsulates the outcome of a computation along with its success status and any associated error message. The class uses generics, allowing it to work with different types of values.
Here's a breakdown of what the class does:
-
Properties: The class has four properties:
isSuccess
,isFailure
,error
, and_value
.isSuccess
indicates whether the operation was successful,isFailure
is the opposite ofisSuccess
,error
contains any error message if the operation failed, and_value
holds the actual value of the operation if it succeeded. -
Constructor: The constructor takes three parameters:
isSuccess
,error
, andvalue
. It checks for invalid states where a successful result has an error, or a failing result doesn't have an error. If such conditions are met, it throws an error. -
getValue: This method returns the value of the operation if it was successful. If the operation wasn't successful, it throws an error.
-
ok: This static method creates a new
Result
instance representing a successful operation. It takes an optionalvalue
parameter. -
fail: This static method creates a new
Result
instance representing a failed operation. It requires anerror
parameter. -
combine: This static method takes an array of
Result
instances and returns the first failure it finds, or a successful result if there are no failures.
This class is a good way to handle operations that can either succeed or fail, providing a clear and consistent way to check the result of an operation and handle errors.
- PicPay Desafio Back-End
- Why we need design patterns
- Refactoring Guru
- Types of software testing
- PHP static analysis tools
- Martin Fowler - Microservices
- REST Tutorial
- Vitest - Getting started
- How to Setup a TypeScript + Node.js Project
- The 5 commandments of clean error handling in TypeScript
- Handling errors like a pro in TypeScript
- Database table relationships
- Flexible Error Handling w/ the Result Class | Enterprise Node.js + TypeScript