Skip to content

Instantly share code, notes, and snippets.

@douglasrafael
Created July 24, 2017 15:31
Show Gist options
  • Select an option

  • Save douglasrafael/df355d0efdf2dda701131d2ca95a3ad9 to your computer and use it in GitHub Desktop.

Select an option

Save douglasrafael/df355d0efdf2dda701131d2ca95a3ad9 to your computer and use it in GitHub Desktop.
Aula 2 - Exercício 4
<% 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 %>
// 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')
})
<% 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 %>
@tuliofaria
Copy link

Certinho.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment