Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 1 addition & 14 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2

end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{html,groovy,java,xml}]
indent_style = space
indent_size = 4
8 changes: 8 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
APPLICATION_NAME='challenge node belezanaweb'
APP_PORT=
NODE_ENV=

MYSQL_DB_SERVERS=
MYSQL_DB_NAME=
MYSQL_DB_USERNAME=
MYSQL_DB_PASSWORD=
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
logs
28 changes: 28 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module.exports = {
env: {
node: true,
jest: true,
es6: true
},
extends: ['standard', 'prettier'],
plugins: ['prettier'],
ignorePatterns: ['.eslintrc.js', 'jest.config.js'],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module'
},
rules: {
semi: ['error', 'always'],
'no-extra-boolean-cast': 'off',
indent: ['error', 2],
'comma-spacing': ['error', { before: false, after: true }],
quotes: ['error', 'single'],
'object-curly-spacing': [1, 'always'],
'no-undef': 'off',
'one-var': 'off',
'no-unused-vars': ['warn', { vars: 'all', args: 'after-used', ignoreRestSiblings: false }],
camelcase: 'off',
'no-console': 'warn',
'comma-dangle': ['error', 'never']
}
};
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,5 @@ typings/

# DynamoDB Local files
.dynamodb/

.vscode/
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn commitlint --edit
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn format
yarn lint
4 changes: 4 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

yarn test
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
coverage
logs
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 140,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": true,
"semi": true,
"useTabs": false,
"endOfLine": "auto"
}
8 changes: 8 additions & 0 deletions .sequelizerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require('path');

module.exports = {
config: path.resolve(__dirname, 'config', 'database.js'),
'migrations-path': 'src/infra/database/migrations',
'models-path': 'src/infra/database/models',
'seeders-path': 'src/infra/database/seeds'
};
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- "11.11.0"
- '11.11.0'
notifications:
email: false
28 changes: 28 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Descrição sobre o projeto

## Framework Awilix

No projeto utilizo o framework Awilix que aplica os principios de Injeção de Dependecia, assim não preciso ficar dando require nos arquivos constantemete e além disso permite injetar as depedencias conforme o contexto.

## Convensões, padronização e dependencias

O projeto usa as conversões de commit: feat para novas funcionalidades, refactor para melhorias, fix para correções, chore quando há alguma alteração não relacionada a aplicação como por exemplo eslint, gitignore, test para implementação de testes, [mais informação](https://www.conventionalcommits.org/en/v1.0.0/)

A padronização e formatação do código são feitas utilizando o eslint, prettier e editorconfig para garantir que toda a escrita de código seja seguindo essas expecificações.

#### Commit Lint e commitizen

Recurso para garantir que escrita de commit sejam de acordo com a convesão e padrão do guia commit conventional

#### Husky

Husky é um recurso/ações para Git Hooks que podem serem lançados antes do commit (pre-commit), antes do push (pre-push) e em outras ocasiões.
Antes de instalar o husky deve ter o git configurado no projeto `git init` e adicionar o husky no projeto `npm install husky --save-dev` ou `yarn add husky --dev`

Adicionando o husky ao git hooks `npx husky install` ou para executar de forma de script `npm pkg set scripts.prepare="husky install"` com o comando `npm run prepare` ou `yarn prepare`.

É importante garantir que as permissões do husky `chmod ug+x .husky/*`, e criar um hook `npx husky add .husky/pre-commit "npm test"`, para testar o hook basta adicionar o(s) arquivos ao commit `git add .husky/pre-commit` e escrever o commit `git commit -m "add pre-commit husky sample"`, com isso o npm test executará antes do commit, dentro do projeto o uso está focado em executar o lint antes do commit `npx husky add .husky/pre-commit "yarn lint"`

#### Jest

Jest é um framework completo para testes e será usado nesse projeto para fazer testes unitários
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
### Backend Test

[![Build Status](https://travis-ci.org/belezanaweb/test-nodejs.svg?branch=master)](https://travis-ci.org/belezanaweb/test-nodejs)

Esta é uma avaliação básica de código.
Expand All @@ -17,24 +18,24 @@ Com a seguinte representação de produto:

```json
{
"sku": 43264,
"name": "L'Oréal Professionnel Expert Absolut Repair Cortex Lipidium - Máscara de Reconstrução 500g",
"inventory": {
"quantity": 15,
"warehouses": [
{
"locality": "SP",
"quantity": 12,
"type": "ECOMMERCE"
},
{
"locality": "MOEMA",
"quantity": 3,
"type": "PHYSICAL_STORE"
}
]
},
"isMarketable": true
"sku": 43264,
"name": "L'Oréal Professionnel Expert Absolut Repair Cortex Lipidium - Máscara de Reconstrução 500g",
"inventory": {
"quantity": 15,
"warehouses": [
{
"locality": "SP",
"quantity": 12,
"type": "ECOMMERCE"
},
{
"locality": "MOEMA",
"quantity": 3,
"type": "PHYSICAL_STORE"
}
]
},
"isMarketable": true
}
```

Expand All @@ -50,7 +51,6 @@ Crie endpoints para as seguintes ações:

### Requisitos


- [ ] Toda vez que um produto for recuperado por **sku** deverá ser calculado a propriedade: **inventory.quantity**

A propriedade inventory.quantity é a soma da quantity dos warehouses
Expand All @@ -63,7 +63,6 @@ Crie endpoints para as seguintes ações:

Dois produtos são considerados iguais se os seus skus forem iguais


- [ ] Ao atualizar um produto, o antigo deve ser sobrescrito com o que esta sendo enviado na requisição

A requisição deve receber o sku e atualizar com o produto que tbm esta vindo na requisição
Expand Down
108 changes: 108 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 100],
'header-max-length': [2, 'always', 300],
'subject-case': [2, 'never', []],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [2, 'always', ['build', 'chore', 'docs', 'feat', 'fix', 'refactor', 'revert', 'test']]
},
prompt: {
questions: {
type: {
description: 'Select the type of change that you are committing',
enum: {
feat: {
description: 'A new feature',
title: 'Features',
emoji: '✨'
},
fix: {
description: 'A bug fix',
title: 'Bug Fixes',
emoji: '🐛'
},
docs: {
description: 'Documentation only changes',
title: 'Documentation',
emoji: '📚'
},
style: {
description: 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)',
title: 'Styles',
emoji: '💎'
},
refactor: {
description: 'A code change that neither fixes a bug nor adds a feature',
title: 'Code Refactoring',
emoji: '📦'
},
perf: {
description: 'A code change that improves performance',
title: 'Performance Improvements',
emoji: '🚀'
},
test: {
description: 'Adding missing tests or correcting existing tests',
title: 'Tests',
emoji: '🚨'
},
build: {
description: 'Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)',
title: 'Builds',
emoji: '🛠'
},
ci: {
description: 'Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)',
title: 'Continuous Integrations',
emoji: '⚙️'
},
chore: {
description: 'Other changes that does not modify src or test files',
title: 'Chores',
emoji: '♻️'
},
revert: {
description: 'Reverts a previous commit',
title: 'Reverts',
emoji: '🗑'
}
}
},
scope: {
description: 'What is the scope of this change (e.g. component or file name)'
},
subject: {
description: 'Write a short, imperative tense description of the change'
},
body: {
description: 'Provide a longer description of the change'
},
isBreaking: {
description: 'Are there any breaking changes?'
},
breakingBody: {
description: 'A BREAKING CHANGE commit requires a body. Please enter a longer description of the commit itself'
},
breaking: {
description: 'Describe the breaking changes'
},
isIssueAffected: {
description: 'Does this change affect any open issues?'
},
issuesBody: {
description: 'If issues are closed, the commit requires a body. Please enter a longer description of the commit itself'
},
issues: {
description: 'Add issue references (e.g. "fix #123", "re #123".)'
}
}
}
};
16 changes: 16 additions & 0 deletions config/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"application": {
"serviceName": "$APPLICATION_NAME",
"port": "$APP_PORT",
"nodeEnv": "$NODE_ENV"
},
"infra": {
"db": {
"username": "$MYSQL_DB_USERNAME",
"password": "$MYSQL_DB_PASSWORD",
"database": "$MYSQL_DB_NAME",
"host": "$MYSQL_DB_SERVERS",
"dialect": "mysql"
}
}
}
29 changes: 29 additions & 0 deletions config/convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function convert(config) {
const result = {};
Object.keys(config).forEach((name) => {
let value = config[name];

if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
value = convert(value);
}

if (typeof value === 'string' && value.indexOf('$') > -1) {
const key = value.replace(/\$/g, '');

if (process.env[key]) {
value = process.env[key];

if (value === 'true') value = true;
if (value === 'false') value = false;
} else {
value = undefined;
}
}

result[name] = value;
});

return result;
}

module.exports = convert;
14 changes: 14 additions & 0 deletions config/database.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require('dotenv').config();

const databaseConfig = {
default: {
dialect: 'mysql',
database: process.env.MYSQL_DB_NAME,
username: process.env.MYSQL_DB_USERNAME,
password: process.env.MYSQL_DB_PASSWORD,
logging: false,
host: process.env.MYSQL_DB_SERVERS
}
};

module.exports = databaseConfig.default;
4 changes: 4 additions & 0 deletions config/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const config = require('./config');
const convert = require('./convert');

module.exports = convert(config);
Loading