Skip to content

Backend test - Junior Barros #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
506d0f4
First: created project and initial documentation file
Sylvn001 Nov 18, 2022
0cbbe12
build: installation of dependencies files (prisma, reflect-metadata,...)
Sylvn001 Nov 18, 2022
2a29f9a
build: created prismaORM config file
Sylvn001 Nov 18, 2022
5992a77
feat: dockerfile and docker-compose configurations
Sylvn001 Nov 18, 2022
331f8ea
chore: add new dependencies, changes in ts-config, prettierrc, gitignore
Sylvn001 Nov 20, 2022
02ca2f4
build: configurated docker files and entrypoints to run db postgres, …
Sylvn001 Nov 20, 2022
7e768ea
chore: add prisma configuration file
Sylvn001 Nov 20, 2022
aa7b846
docs: fix documentation template and included user-guide to run app
Sylvn001 Nov 20, 2022
51e2cd8
feat: created investiments module
Sylvn001 Nov 20, 2022
16bb060
chore: add prisma dependencies, swagger and more
Sylvn001 Nov 21, 2022
1bce6a8
build: changed entrypoint command and docker-compose port
Sylvn001 Nov 21, 2022
4817919
feat: updated prisma schema and generated migration file
Sylvn001 Nov 21, 2022
924fa7e
feat: updated module, add swagger config and prisma service layer
Sylvn001 Nov 21, 2022
94c74b3
feat: created owner module
Sylvn001 Nov 21, 2022
456a43e
feat: create endpoint of findAll and create investment
Sylvn001 Nov 21, 2022
c4c5a43
feat: implemented validation of invalid date
Sylvn001 Nov 21, 2022
d4d838e
chore: installation of cron packages and updated .env.example
Sylvn001 Nov 21, 2022
8fb3b50
build: changes on dockerfile to be compatible with windows and linux …
Sylvn001 Nov 21, 2022
dbd2340
docs: updated readme
Sylvn001 Nov 21, 2022
8cb4e1e
feat: improve methods to insert a new investment, view, and withdraw
Sylvn001 Nov 21, 2022
93de625
feat: implemented validation schedule rules
Sylvn001 Nov 21, 2022
7f9ec8b
feat: updated calculateDailyGain rules and validation of month
Sylvn001 Nov 21, 2022
a225f6e
feat: implemented diffDAys in calculation of tax
Sylvn001 Nov 22, 2022
aed604d
feat: add calculations of date and validations. Fix investments funct…
Sylvn001 Nov 22, 2022
3197ccc
fix: remove commented line for test
Sylvn001 Nov 22, 2022
5dccd09
docs: improve documentation of project
Sylvn001 Nov 22, 2022
732a9e3
fix: improve documentation and fix invalid values of swagger
Sylvn001 Nov 22, 2022
61f7325
chore: fix nest-cli to build .hbs files and new packages of nodemailer
Sylvn001 Nov 22, 2022
cae012f
feat: implemented sendMailTo when a investment amount are updated
Sylvn001 Nov 22, 2022
06a6560
chore: installation of packages for test
Sylvn001 Nov 22, 2022
763f9d9
feat: fix dto dir and initial configs for test
Sylvn001 Nov 22, 2022
58fe0b8
chore: packages for mock test and prismaORM
Sylvn001 Nov 22, 2022
9c14bc7
docs: include postman endpoints
Sylvn001 Nov 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions AboutBackendTest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Back End Test Project <img src="https://coderockr.com/assets/images/coderockr.svg" align="right" height="50px" />

You should see this challenge as an opportunity to create an application following modern development best practices (given the stack of your choice), but also feel free to use your own architecture preferences (coding standards, code organization, third-party libraries, etc). It’s perfectly fine to use vanilla code or any framework or libraries.

## Scope

In this challenge you should build an API for an application that stores and manages investments, it should have the following features:

1. __Creation__ of an investment with an owner, a creation date and an amount.
1. The creation date of an investment can be today or a date in the past.
2. An investment should not be or become negative.
2. __View__ of an investment with its initial amount and expected balance.
1. Expected balance should be the sum of the invested amount and the [gains][].
2. If an investment was already withdrawn then the balance must reflect the gains of that investment
3. __Withdrawal__ of a investment.
1. The withdraw will always be the sum of the initial amount and its gains,
partial withdrawn is not supported.
2. Withdrawals can happen in the past or today, but can't happen before the investment creation or the future.
3. [Taxes][taxes] need to be applied to the withdrawals before showing the final value.
4. __List__ of a person's investments
1. This list should have pagination.

__NOTE:__ the implementation of an interface will not be evaluated.

### Gain Calculation

The investment will pay 0.52% every month in the same day of the investment creation.

Given that the gain is paid every month, it should be treated as [compound gain][], which means that every new period (month) the amount gained will become part of the investment balance for the next payment.

### Taxation

When money is withdrawn, tax is triggered. Taxes apply only to the profit/gain portion of the money withdrawn. For example, if the initial investment was 1000.00, the current balance is 1200.00, then the taxes will be applied to the 200.00.

The tax percentage changes according to the age of the investment:
* If it is less than one year old, the percentage will be 22.5% (tax = 45.00).
* If it is between one and two years old, the percentage will be 18.5% (tax = 37.00).
* If older than two years, the percentage will be 15% (tax = 30.00).

## Requirements
1. Create project using any technology of your preference. It’s perfectly OK to use vanilla code or any framework or libraries;
2. Although you can use as many dependencies as you want, you should manage them wisely;
3. It is not necessary to send the notification emails, however, the code required for that would be welcome;
4. The API must be documented in some way.

## Deliverables
The project source code and dependencies should be made available in GitHub. Here are the steps you should follow:
1. Fork this repository to your GitHub account (create an account if you don't have one, you will need it working with us).
2. Create a "development" branch and commit the code to it. Do not push the code to the main branch.
3. Include a README file that describes:
- Special build instructions, if any
- List of third-party libraries used and short description of why/how they were used
- A link to the API documentation.
4. Once the work is complete, create a pull request from "development" into "main" and send us the link.
5. Avoid using huge commits hiding your progress. Feel free to work on a branch and use `git rebase` to adjust your commits before submitting the final version.

## Coding Standards
When working on the project be as clean and consistent as possible.

## Project Deadline
Ideally you'd finish the test project in 5 days. It shouldn't take you longer than a entire week.

## Quality Assurance
Use the following checklist to ensure high quality of the project.

### General
- First of all, the application should run without errors.
- Are all requirements set above met?
- Is coding style consistent?
- The API is well documented?
- The API has unit tests?

## Submission
1. A link to the Github repository.
2. Briefly describe how you decided on the tools that you used.

## Have Fun Coding 🤘
- This challenge description is intentionally vague in some aspects, but if you need assistance feel free to ask for help.
- If any of the seems out of your current level, you may skip it, but remember to tell us about it in the pull request.

## Credits

This coding challenge was inspired on [kinvoapp/kinvo-back-end-test](https://github.com/kinvoapp/kinvo-back-end-test/blob/2f17d713de739e309d17a1a74a82c3fd0e66d128/README.md)

[gains]: #gain-calculation
[taxes]: #taxation
[interest]: #interest-calculation
[compound gain]: https://www.investopedia.com/terms/g/gain.asp
111 changes: 42 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,61 @@
# Back End Test Project <img src="https://coderockr.com/assets/images/coderockr.svg" align="right" height="50px" />
# App Investiments - Backend Test

You should see this challenge as an opportunity to create an application following modern development best practices (given the stack of your choice), but also feel free to use your own architecture preferences (coding standards, code organization, third-party libraries, etc). It’s perfectly fine to use vanilla code or any framework or libraries.
> App for investments, created for show my skills on backend.

## Scope
### 💻 Node.js - Version

In this challenge you should build an API for an application that stores and manages investments, it should have the following features:
<p align="center">
<a href="#%EF%B8%8F-tecnologies">Tecnologies</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="#-project">Project</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="#-how-Start">How Start</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="#-Docs">Docs</a>
<a href="#-license">License</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
<a href="#atom_symbol-follow-me">Follow Me!</a>
</p>

1. __Creation__ of an investment with an owner, a creation date and an amount.
1. The creation date of an investment can be today or a date in the past.
2. An investment should not be or become negative.
2. __View__ of an investment with its initial amount and expected balance.
1. Expected balance should be the sum of the invested amount and the [gains][].
2. If an investment was already withdrawn then the balance must reflect the gains of that investment
3. __Withdrawal__ of a investment.
1. The withdraw will always be the sum of the initial amount and its gains,
partial withdrawn is not supported.
2. Withdrawals can happen in the past or today, but can't happen before the investment creation or the future.
3. [Taxes][taxes] need to be applied to the withdrawals before showing the final value.
4. __List__ of a person's investments
1. This list should have pagination.
![image](https://user-images.githubusercontent.com/50564121/163297818-11a4d919-58a0-4b2b-b65e-110d3aa55f72.png)

__NOTE:__ the implementation of an interface will not be evaluated.
## ⚒️ Tecnologies

### Gain Calculation
- [Nestjs](https://docs.nestjs.com/)
- [Jest](https://jestjs.io/)
- [PrismaORM](https://www.prisma.io/)
- [Typescript](https://www.typescriptlang.org/)
- [Docker Engine](https://docs.docker.com/get-started/)

The investment will pay 0.52% every month in the same day of the investment creation.
## 💻 Project

Given that the gain is paid every month, it should be treated as [compound gain][], which means that every new period (month) the amount gained will become part of the investment balance for the next payment.
This project as developed with purpose to show my programming skills to a backend test

### Taxation
## 🚀 How start

When money is withdrawn, tax is triggered. Taxes apply only to the profit/gain portion of the money withdrawn. For example, if the initial investment was 1000.00, the current balance is 1200.00, then the taxes will be applied to the 200.00.
- Open project folder (app) `cd ./app`
- Run docker build `docker-compose build`
- Run docker project using `docker-compose up`
- Note: To open bash you can use `docker-compose exec app bash` - Docker Bash is necessary to run [PrismaORM](https://www.prisma.io/) migrations. You need open bash and run migrations using command `npx prisma migrate dev`.
- Note: if you use linux -> in terminal run `chmod +x .docker/entrypoint.sh` to get permission of execute.
- Note: (windows) if you have error "standard_init_linux.go:228: exec user process caused: no such file or directory. Change EOL in Dockerfile, entrypoint.sh to LF.
- [Optional]: You can also run this application whitout docker. If you try it open app folder and run 1. `yarn` 2. `npx prisma migrate dev` 3. `yarn start:dev`
- [Env]: Check if `.env` is configured, you need create a new file with `.env` name and copy and paste `.env.example` informations to `.env` file and configure based on you local dependencies

The tax percentage changes according to the age of the investment:
* If it is less than one year old, the percentage will be 22.5% (tax = 45.00).
* If it is between one and two years old, the percentage will be 18.5% (tax = 37.00).
* If older than two years, the percentage will be 15% (tax = 30.00).
"

## Requirements
1. Create project using any technology of your preference. It’s perfectly OK to use vanilla code or any framework or libraries;
2. Although you can use as many dependencies as you want, you should manage them wisely;
3. It is not necessary to send the notification emails, however, the code required for that would be welcome;
4. The API must be documented in some way.
## 🕸️ Test in WEB

## Deliverables
The project source code and dependencies should be made available in GitHub. Here are the steps you should follow:
1. Fork this repository to your GitHub account (create an account if you don't have one, you will need it working with us).
2. Create a "development" branch and commit the code to it. Do not push the code to the main branch.
3. Include a README file that describes:
- Special build instructions, if any
- List of third-party libraries used and short description of why/how they were used
- A link to the API documentation.
4. Once the work is complete, create a pull request from "development" into "main" and send us the link.
5. Avoid using huge commits hiding your progress. Feel free to work on a branch and use `git rebase` to adjust your commits before submitting the final version.
Open Browser in [`localhost:3000`](http://localhost:3000).

## Coding Standards
When working on the project be as clean and consistent as possible.
# 📚 Docs

## Project Deadline
Ideally you'd finish the test project in 5 days. It shouldn't take you longer than a entire week.
- OpenApi 3.0 Using Swagger
- Check Documentation Here [AppInvestments](localhost:3000/api)
- Note: you need run project to view documentation

## Quality Assurance
Use the following checklist to ensure high quality of the project.
## 📝 License

### General
- First of all, the application should run without errors.
- Are all requirements set above met?
- Is coding style consistent?
- The API is well documented?
- The API has unit tests?
This project use a <a href="./LICENSE"> MIT </a> License

## Submission
1. A link to the Github repository.
2. Briefly describe how you decided on the tools that you used.
## :atom_symbol: Follow me!

## Have Fun Coding 🤘
- This challenge description is intentionally vague in some aspects, but if you need assistance feel free to ask for help.
- If any of the seems out of your current level, you may skip it, but remember to tell us about it in the pull request.

## Credits

This coding challenge was inspired on [kinvoapp/kinvo-back-end-test](https://github.com/kinvoapp/kinvo-back-end-test/blob/2f17d713de739e309d17a1a74a82c3fd0e66d128/README.md)

[gains]: #gain-calculation
[taxes]: #taxation
[interest]: #interest-calculation
[compound gain]: https://www.investopedia.com/terms/g/gain.asp
- Instagram: https://www.instagram.com/sylvn001/
- Twitch: https://www.twitch.tv/sylvn001
- GitHub: https://github.com/Sylvn001
6 changes: 6 additions & 0 deletions app/.docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

npm install
npm run build
npx prisma migrate deploy
npm run start:dev
3 changes: 3 additions & 0 deletions app/.docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM postgres

RUN usermod -u 1000 postgres
8 changes: 8 additions & 0 deletions app/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
DATABASE_URL="postgresql://postgres:postgres123@db:5432/appdb?schema=public"

MAIL_HOST="smtp.ethereal.email"
MAIL_USER="milan.jacobson@ethereal.email"
MAIL_PASSWORD="7EPPyYUbw5ZqCaxdUE"
MAIL_FROM="noreply@example.com"

# USE ETHEREAL TO CONFIG https://ethereal.email/create
25 changes: 25 additions & 0 deletions app/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
project: 'tsconfig.json',
tsconfigRootDir : __dirname,
sourceType: 'module',
},
plugins: ['@typescript-eslint/eslint-plugin'],
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
],
root: true,
env: {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
},
};
39 changes: 39 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

.env
.docker/dbdata
.docker/dbdatatest
7 changes: 7 additions & 0 deletions app/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"trailingComma": "all",
"semi": true,
"printWidth": 80,
"arrowParens": "avoid"
}
11 changes: 11 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:lts-alpine

RUN apk add --no-cache bash

RUN npm install -g @nestjs/cli

ENV TZ="America/Sao_Paulo"

USER node

WORKDIR /home/node/app
Loading