Backend - Users && more stuff#64
Conversation
- 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 vou dar uma olhada nisso e dar merge! |
README.md
Outdated
| 2. Rode as migrations | ||
|
|
||
| ```sh | ||
| $ npm run knex migrate:latest |
There was a problem hiding this comment.
O lugar disto seria na documentação da wiki https://github.com/nodebr/nodebr/wiki/Backend
There was a problem hiding this comment.
Depois coloco lá então 👍
index.js
Outdated
| @@ -1,5 +1,7 @@ | |||
| 'use strict' | |||
|
|
|||
| require('dotenv').config() | |||
There was a problem hiding this comment.
Não utilizar o dotenv, os desenvolvedores podem fazer o source do .env caso seja necessário
lib/db/knexfile.js
Outdated
|
|
||
| const path = require('path') | ||
|
|
||
| require('dotenv').config({ path: path.resolve(__dirname, '../../.env') }) |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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') { |
resources/users/handlers.js
Outdated
| const db = require('../../lib/db') | ||
| const User = db.model('User') | ||
|
|
||
| exports.findAll = (req, res) => { |
resources/users/routes.js
Outdated
|
|
||
| const router = express.Router() | ||
|
|
||
| router.get('/users', handlers.findAll) |
resources/users/routes.js
Outdated
| const router = express.Router() | ||
|
|
||
| router.get('/users', handlers.findAll) | ||
| router.get('/users/:id', handlers.findOne) |
resources/users/schemas.js
Outdated
|
|
||
| exports.create = exports.model.concat(Joi.object({ | ||
| id: Joi.forbidden(), | ||
| username: Joi.string().alphanum().min(3).max(20).required(), |
There was a problem hiding this comment.
Utilizar .token no lugar de .alphanum, assim podemos criar usernames com underscore também
resources/users/schemas.js
Outdated
| 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() |
Ajustando resource
Current coverage is 96.14% (diff: 96.22%)@@ 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
|
alanhoff
left a comment
There was a problem hiding this comment.
Faltando testes para:
- Nome de usuário duplicado
- Se a senha foi realmente criptografada
| @@ -0,0 +1,13 @@ | |||
|
|
|||
| @@ -0,0 +1,13 @@ | |||
|
|
|||
| exports.up = knex => { | |||
There was a problem hiding this comment.
Não precisa criar um escopo com as chaves aqui, pode simplesmente knex => knex.schema...
| }) | ||
| } | ||
|
|
||
| exports.down = knex => { |
resources/users/handlers.js
Outdated
| @@ -0,0 +1,17 @@ | |||
|
|
|||
resources/users/model.js
Outdated
| @@ -0,0 +1,6 @@ | |||
|
|
|||
resources/users/routes.js
Outdated
| @@ -0,0 +1,16 @@ | |||
|
|
|||
test/fixtures/users.js
Outdated
| @@ -0,0 +1,27 @@ | |||
| 'use strict' | |||
test/fixtures/users.js
Outdated
| * Insere dois registros na tabela hello_world | ||
| * @return {Promise} Uma promise que resolve quando os registros forem inseridos | ||
| */ | ||
| exports.insertMultiple = () => { |
There was a problem hiding this comment.
não precisa criar um escopo e um return
test/fixtures/users.js
Outdated
| const { knex } = require('../../lib/db') | ||
|
|
||
| /** | ||
| * Insere dois registros na tabela hello_world |
test/resources/users.js
Outdated
| @@ -0,0 +1,46 @@ | |||
| 'use strict' | |||
There was a problem hiding this comment.
Remover o use strict daqui também
|
LGMT |

.envwithdotenvmodulemorganto print request logsusersresourcehello-worldstructure'use strict'thingies because es6 modules are strict by default :Pemailis not in the specification but probably very important (?)passwordis currently saved raw, missing bcrypt stuff