diff --git a/controllers/home.js b/controllers/home.js index a07fce4..f5de7a9 100644 --- a/controllers/home.js +++ b/controllers/home.js @@ -14,6 +14,7 @@ module.exports = function(app) { 'projects.name', 'projects.description', 'projects.goal_amount', + 'projects.goal_due', 'project_addresses.token' ]) .from('projects') diff --git a/controllers/projects/add.js b/controllers/projects/add.js index f9d6762..24a7d5c 100644 --- a/controllers/projects/add.js +++ b/controllers/projects/add.js @@ -14,6 +14,7 @@ module.exports = function(app) { name : req.body.name, description : req.body.description, goal_amount : req.body.amount, + goal_due : req.body.due }) .then(function(result){ app.db('project_addresses') diff --git a/controllers/projects/edit.js b/controllers/projects/edit.js index 9faf763..545521d 100644 --- a/controllers/projects/edit.js +++ b/controllers/projects/edit.js @@ -20,6 +20,7 @@ module.exports = function(app) { name : result[0].name, description : result[0].description, amount : result[0].goal_amount, + due : result[0].goal_due, token : result[0].token }); }); @@ -35,6 +36,7 @@ module.exports = function(app) { name : req.body.name, description : req.body.description, goal_amount : req.body.amount, + goal_due : req.body.due, }) .then(function(result){ app.db('project_addresses') diff --git a/models/Projects.js b/models/Projects.js index c8e41b3..11032b8 100644 --- a/models/Projects.js +++ b/models/Projects.js @@ -1,6 +1,7 @@ 'use strict'; var BaseModel = require('./BaseModel'); +var db = require('../database'); module.exports = BaseModel.extend({ @@ -14,6 +15,22 @@ module.exports = BaseModel.extend({ table.string('name'); table.string('description'); table.decimal('goal_amount', 16, 8); + table.date('goal_due'); } }); + +// schema migrations to be run at the server startup. 'return' each db call, otherwise it's not executed +module.exports.queueSchemaChange(function(cb) { + + return db.schema.hasColumn('projects', 'goal_due').then(function(exists) { + if (!exists) { + return db.schema.table('projects', function(table) { + table.date('goal_due'); + }); + } + }).then(function() { + cb(); + }) + +}); \ No newline at end of file diff --git a/scripts/seed_projects.js b/scripts/seed_projects.js index 0a42c83..b50237e 100644 --- a/scripts/seed_projects.js +++ b/scripts/seed_projects.js @@ -7,7 +7,7 @@ var fs = require('fs'); var contents = fs.readFileSync("./test/fixtures/projects.json"); // Define to JSON type var seed_data = JSON.parse(contents); -projects = seed_data.projects; +var projects = seed_data.projects; function seed() { @@ -16,7 +16,8 @@ function seed() { .insert({ name: project.name, description: project.description, - goal_amount: project.goal_amount + goal_amount: project.goal_amount, + goal_due: project.goal_due }).then(function(result) { db('project_addresses') .insert({ diff --git a/test/fixtures/projects.json b/test/fixtures/projects.json index eaf93cc..e911a1b 100644 --- a/test/fixtures/projects.json +++ b/test/fixtures/projects.json @@ -4,19 +4,22 @@ "name" : "Project1", "description" : "Description for Project1.", "goal_amount" : 100, - "token" : "16TAy1uNFNEw58uPN4c7C8VnJUYp2ZJUjd" + "token" : "16TAy1uNFNEw58uPN4c7C8VnJUYp2ZJUjd", + "goal_due": "2019-01-21" }, { "name" : "Project2", "description" : "Description for Project2.", "goal_amount" : 200, - "token" : "1Nkk6rPhFk5UbbNWT12QyCTosgjV8MWjeg" + "token" : "1Nkk6rPhFk5UbbNWT12QyCTosgjV8MWjeg", + "goal_due": "2019-01-22" }, { "name" : "Project3", "description" : "Description for Project3.", "goal_amount" : 300, - "token" : "1BHPGY7Rb9WaBBkYPKjZTnKYRzt5mC8NPM" + "token" : "1BHPGY7Rb9WaBBkYPKjZTnKYRzt5mC8NPM", + "goal_due": "2019-01-23" } ] } diff --git a/views/home.html b/views/home.html index 5c785c5..cb8be7f 100644 --- a/views/home.html +++ b/views/home.html @@ -38,7 +38,7 @@

Projects Index

  • Goal: - {{goal_amount}} + Raise {{goal_amount}} BTC by {{goal_due}}
  • Address: diff --git a/views/projects-add.html b/views/projects-add.html index 007a13b..b13fee3 100644 --- a/views/projects-add.html +++ b/views/projects-add.html @@ -7,6 +7,8 @@ + + diff --git a/views/projects-edit.html b/views/projects-edit.html index 7dbe1ec..8b8b440 100644 --- a/views/projects-edit.html +++ b/views/projects-edit.html @@ -7,6 +7,8 @@ + +