Skip to content

Commit 62f2be6

Browse files
committed
post info now populates on homepage
1 parent 11e7543 commit 62f2be6

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

controllers/homeRoutes.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
const router = require("express").Router();
2-
const User = require("../models/User");
3-
2+
const { Post, User } = require("../models");
43
const withAuth = require("../utils/auth");
54

65
router.get("/", withAuth, async (req, res) => {
76
try {
8-
// creates a users object for admin dashboard reporting
9-
const userData = await User.findAll({
10-
attributes: { exclude: ["password"] },
11-
order: [["username", "ASC"]],
7+
// gets all posts to display on the page
8+
const postData = await Post.findAll({
9+
attributes: ["title", "text", "createdAt"],
1210
});
1311

14-
const users = userData.map((project) => project.get({ plain: true }));
12+
const posts = postData.map((post) => post.get({ plain: true }));
1513

16-
console.log(users);
1714
res.render("dashboard", {
15+
posts,
1816
//pass data into page
1917
logged_in: req.session.logged_in,
2018
username: req.session.username,

models/Post.js

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Post.init(
1515
primaryKey: true,
1616
autoIncrement: true,
1717
},
18+
title: {
19+
type: DataTypes.STRING,
20+
},
1821
text: {
1922
type: DataTypes.STRING,
2023
},

seeds/postData.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[
22
{
33
"id": 1,
4+
"title": "Sample Title",
45
"text": "This is a sample post",
56
"user_id": 1
67
}

views/dashboard.handlebars

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<h2>dash</h2>
1+
<h2>dash</h2>
2+
3+
{{>posts}}

views/partials/posts.handlebars

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>
2+
<h3>Posts</h3>
3+
</div>
4+
5+
{{#each posts}}
6+
<div class="card">
7+
<h3>{{title}}</h3>
8+
<p>{{text}}</p>
9+
</div>
10+
{{/each}}

0 commit comments

Comments
 (0)