Browse Source

added conversion of datetime to template

Issue #1

since sqlite is storing the timestamp as UTC, the template is now handling the conversion to localtime itself.

additionally, the db select statements were changed to specify the exact data instead of selecting *.
this is to ensure the data returned is as expected if the schema is changed and the queries are not updated.
master
Blaine Motsinger 1 year ago
parent
commit
2237850cae
4 changed files with 5 additions and 4 deletions
  1. 1
    1
      notes.js
  2. 1
    1
      routes/api/notes.js
  3. 1
    1
      routes/index.js
  4. 2
    1
      views/index.pug

+ 1
- 1
notes.js View File

@@ -3,7 +3,7 @@

"use strict";

const version = '1.0.0';
const version = '1.0.1';

const express = require( 'express' );
const moment = require( 'moment' );

+ 1
- 1
routes/api/notes.js View File

@@ -9,7 +9,7 @@ const dbh = require( './../../lib/dbh' );
router.get( '/', function ( req, res ) {

// get all of the notes
dbh.all( 'SELECT * from notes', function( err, rows ) {
dbh.all( 'SELECT id, note, created_at from notes', function( err, rows ) {

res.status( 200 )
.header( 'Content-Type', 'application/json' )

+ 1
- 1
routes/index.js View File

@@ -9,7 +9,7 @@ const dbh = require( './../lib/dbh' );
router.get( '/', function ( req, res ) {

// get all of the notes
dbh.all( 'SELECT * from notes', function( err, rows ) {
dbh.all( 'SELECT id, note, created_at from notes', function( err, rows ) {

// send to the index.pug view
res.render( 'index', { rows: rows } );

+ 2
- 1
views/index.pug View File

@@ -6,6 +6,7 @@ html(lang="en")
#notes
if rows
each row in rows
p.note #{row.created_at} - #{row.note}
- var date = new Date( row.created_at + ' UTC' );
p.note #{date.toLocaleString()} - #{row.note}
else
p.note There are no notes to be displayed.

Loading…
Cancel
Save