Skip to content

Backend - Users && more stuff#64

Merged
alanhoff merged 15 commits intonodebr:backendfrom
brunops:backend
Nov 15, 2016
Merged

Backend - Users && more stuff#64
alanhoff merged 15 commits intonodebr:backendfrom
brunops:backend

Conversation

@brunops
Copy link
Contributor

@brunops brunops commented Nov 15, 2016

  • Load environment variables from .env with dotenv module
  • Add steps necessary to run the app to the README
  • add morgan to print request logs
  • Add users resource
    • This follows hello-world structure
    • there are no 'use strict' thingies because es6 modules are strict by default :P
    • email is not in the specification but probably very important (?)
    • password is currently saved raw, missing bcrypt stuff

bsanches added 6 commits November 14, 2016 22:39
- This follows `hello-world` structure
- there are no `'use strict'` thingies because commonjs is strict by default :P
- `email` is not in the specification but probably very important (?)
- `password` is currently saved raw, missing bcrypt stuff
@brunops
Copy link
Contributor Author

brunops commented Nov 15, 2016

Os testes não estão rodando por algum motivo, Parece ser relacionado com como aquela .truncate() query está sendo montada. Não consegui descobrir o erro, mas é isso aqui:

screen shot 2016-11-14 at 11 45 11 pm

@thebergamo
Copy link
Member

@brunops vou dar uma olhada nisso e dar merge!

README.md Outdated
2. Rode as migrations

```sh
$ npm run knex migrate:latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O lugar disto seria na documentação da wiki https://github.com/nodebr/nodebr/wiki/Backend

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depois coloco lá então 👍

index.js Outdated
@@ -1,5 +1,7 @@
'use strict'

require('dotenv').config()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não utilizar o dotenv, os desenvolvedores podem fazer o source do .env caso seja necessário

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aurait


const path = require('path')

require('dotenv').config({ path: path.resolve(__dirname, '../../.env') })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não utilizar o dotenv, os desenvolvedores podem fazer o source do .env caso seja necessário


exports.up = knex => {
// Apenas roda esta migration se estivermos em um ambiente de desenvolvimento
if (process.env.NODE_ENV !== 'production') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não precisa deste if aqui, ele estava presente somente na migration do hello-world pois não queremos ela rodando em produção

}

exports.down = knex => {
if (process.env.NODE_ENV !== 'production') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não precisa do if

const db = require('../../lib/db')
const User = db.model('User')

exports.findAll = (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover esta rota e handler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do


const router = express.Router()

router.get('/users', handlers.findAll)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover esta rota e handler

const router = express.Router()

router.get('/users', handlers.findAll)
router.get('/users/:id', handlers.findOne)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover esta rota e handler


exports.create = exports.model.concat(Joi.object({
id: Joi.forbidden(),
username: Joi.string().alphanum().min(3).max(20).required(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilizar .token no lugar de .alphanum, assim podemos criar usernames com underscore também

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bom saber

exports.create = exports.model.concat(Joi.object({
id: Joi.forbidden(),
username: Joi.string().alphanum().min(3).max(20).required(),
password: Joi.string().max(60).required()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.min(8).max(120)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@codecov-io
Copy link

codecov-io commented Nov 15, 2016

Current coverage is 96.14% (diff: 96.22%)

Merging #64 into backend will increase coverage by 0.04%

@@            backend        #64   diff @@
==========================================
  Files            11         15     +4   
  Lines           256        311    +55   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            246        299    +53   
- Misses           10         12     +2   
  Partials          0          0          

Powered by Codecov. Last update bc9f4cf...92833ad

@alanhoff alanhoff dismissed their stale review November 15, 2016 17:36

Novo review

Copy link
Member

@alanhoff alanhoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Faltando testes para:

  • Nome de usuário duplicado
  • Se a senha foi realmente criptografada

@@ -0,0 +1,13 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover a linha em branco

@@ -0,0 +1,13 @@

exports.up = knex => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não precisa criar um escopo com as chaves aqui, pode simplesmente knex => knex.schema...

})
}

exports.down = knex => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mesma questão do escopo

@@ -0,0 +1,17 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover linha em branco

@@ -0,0 +1,6 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linha em branco

@@ -0,0 +1,16 @@

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linha em branco

@@ -0,0 +1,27 @@
'use strict'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover use strict

* Insere dois registros na tabela hello_world
* @return {Promise} Uma promise que resolve quando os registros forem inseridos
*/
exports.insertMultiple = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

não precisa criar um escopo e um return

const { knex } = require('../../lib/db')

/**
* Insere dois registros na tabela hello_world
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentação errada

@@ -0,0 +1,46 @@
'use strict'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remover o use strict daqui também

@alanhoff
Copy link
Member

LGMT

@alanhoff alanhoff merged commit aabd929 into nodebr:backend Nov 15, 2016
@thebergamo thebergamo mentioned this pull request Nov 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants