Created
July 24, 2017 15:31
-
-
Save douglasrafael/df355d0efdf2dda701131d2ca95a3ad9 to your computer and use it in GitHub Desktop.
Aula 2 - Exercício 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% include header %> | |
| <h2>Lista de contas mensal</h2> | |
| <% if(contas.length > 0) { %> | |
| <table border="1"> | |
| <thead> | |
| <tr> | |
| <th>Descrição</th> | |
| <th>Valor Estimado</th> | |
| <th>Dia Vencimento</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <% contas.forEach((conta) => { %> | |
| <tr> | |
| <td><%= conta.descricao %></td> | |
| <td><%= conta.valorEstimado.toFixed(2) %></td> | |
| <td><%= conta.diaVencimento %></td> | |
| </tr> | |
| <% }) %> | |
| </tbody> | |
| </table> | |
| <% } else { %> | |
| <h5>Não existe contas cadastradas!</h5> | |
| <% } %> | |
| <% include footer %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Mostrar contas | |
| app.get('/contas', async (req, res) => { | |
| let contas = await findAll(app.db, 'contas') | |
| res.render('contas', { contas }) | |
| }) | |
| // Mostrar form de contas | |
| app.get('/nova-conta', (req, res) => res.render('nova-conta')) | |
| // Casdatra nova conta | |
| app.post('/nova-conta', async (req, res) => { | |
| let conta = { | |
| descricao: req.body.descricao, | |
| valorEstimado: parseFloat(req.body.valorEstimado), | |
| diaVencimento: req.body.diaVencimento | |
| } | |
| await insert(app.db, 'contas', conta) | |
| res.redirect('/contas') | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <% include header %> | |
| <h2>Cadastro de conta mensal</h2> | |
| <form method="POST"> | |
| Descrição: <input type="text" name="descricao"><br> | |
| Valor Estimado: <input type="text" name="valorEstimado"><br> | |
| Dia do Vencimento: <input type="text" name="diaVencimento"><br> | |
| <button type="submit">Cadastrar</button> | |
| </form> | |
| <% include footer %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho.