const express = require('express');
const router = express.Router();
const Task = require('../models/Tasks')
// @desc GET /dashboard
router.get('/', (req, res) => {
res.render('dashboard')
})
// @desc GET /dashboard/task
router.get('/task', (req, res) => {
res.render('task')
})
// @desc GET /dashboard/fulllist
// router.get('/task/fulllist', async (req, res) => {
// try {
// let tablee = Task.find({
// author: req.body.author
// });
// res.render('fulllist', {
// author: req.body.author,
// table: tablee
// })
// } catch (e) {
// console.log(e)
// }
// })
// @desc POST /dashboard/task
router.post('/task/fulllist', async (req, res) => {
try {
let task = new Task({
title: req.body.title,
author: req.body.author,
body: req.body.body,
createdAt: Date.now()
})
await task.save(task)
let table = Task.find({
author: req.body.author
});
res.render('fulllist', {
author: req.body.author,
table
})
} catch (e) {
console.log(e)
}
})
module.exports = router;
{% extends 'layout.twig' %}
{% block body %}
<h1>Witaj, {{ author }}</h1>
{# <p>{{title}}</p>
<p>{{author}}</p>
<p>{{body}}</p>
<p>{{createdAt}}</p> #}
<table>
{% for item in table %}
<td>{{item}}</td>
{% endfor %}
</table>
{% endblock %}
Witam, mam problem a mianowicie nie wiem czemu zawraca mi [Object object] zamiast całą kolekcje. Ktoś coś wie na ten temat ? Dodatkowo na podstronie /task/fulllist przy odświeżaniu przesyła mi dodatkowy rekord do bazy danych. + jak console.log(table) zwraca mi undefined :/