Skip to content

Commit

Permalink
Sequelize data formatting offers DATE or DATEONLY, we use DATEONLY to…
Browse files Browse the repository at this point in the history
… return just the date. It still could be in better format, but it is much better than that long date string with all of the data data. We updated our model and created the object for the schema for this, and reset the db. Updated created_at to created_on, which is what we named it in our schema.
  • Loading branch information
Christian Martinez committed Jul 28, 2023
1 parent 6cfeeb1 commit 349a8d7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
4 changes: 2 additions & 2 deletions controllers/api/post-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.get('/', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down Expand Up @@ -59,7 +59,7 @@ router.get('/:id', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down
2 changes: 1 addition & 1 deletion controllers/api/user-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ router.post('/login', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down
4 changes: 2 additions & 2 deletions controllers/dashboard-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ router.get('/', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down Expand Up @@ -58,7 +58,7 @@ router.get('/edit/:id', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down
2 changes: 1 addition & 1 deletion controllers/home-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.get('/', async (req, res) => {
'comment_text',
'post_id',
'user_id',
'created_at',
'created_on',
],
include: {
model: User,
Expand Down
5 changes: 5 additions & 0 deletions models/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Comment.init(
len: [1],
},
},
created_on: {
type: DataTypes.DATEONLY,
allowNull: false,
defaultValue: DataTypes.NOW,
},
user_id: {
type: DataTypes.INTEGER,
references: {
Expand Down
5 changes: 4 additions & 1 deletion views/view-post.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
{{#each allComments}}
<div class='p-6'>
"{{this.comment_text}}"
<p class='font-bold'>- {{this.user.dataValues.full_name}}</p>
<p class='font-bold'>-
{{this.user.dataValues.full_name}}
on
{{this.created_on}}</p>
</div>
{{/each}}
</div>
Expand Down

0 comments on commit 349a8d7

Please sign in to comment.