Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #63 deadline of projects funding #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions controllers/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function(app) {
'projects.name',
'projects.description',
'projects.goal_amount',
'projects.goal_due',
'project_addresses.token'
])
.from('projects')
Expand Down
1 change: 1 addition & 0 deletions controllers/projects/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions controllers/projects/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
Expand All @@ -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')
Expand Down
17 changes: 17 additions & 0 deletions models/Projects.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var BaseModel = require('./BaseModel');
var db = require('../database');

module.exports = BaseModel.extend({

Expand All @@ -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();
})

});
5 changes: 3 additions & 2 deletions scripts/seed_projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand All @@ -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({
Expand Down
9 changes: 6 additions & 3 deletions test/fixtures/projects.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
2 changes: 1 addition & 1 deletion views/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ <h2>Projects Index</h2>
</li>
<li>
<span>Goal: </span>
<span>{{goal_amount}}</span>
<span>Raise {{goal_amount}} BTC by {{goal_due}}</span>
</li>
<li>
<span>Address: </span>
Expand Down
2 changes: 2 additions & 0 deletions views/projects-add.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<input id="description" name="description" type="text">
<label for="goal-amount">Goal Amount</label>
<input id="goal-amount" name="amount" type="text">
<label for="goal-due">Goal Due</label>
<input id="goal-due" name="due" type="text">
<label for="token">Token</label>
<input id="token" name="token" type="text">
<input type="submit" value="Add Project">
Expand Down
2 changes: 2 additions & 0 deletions views/projects-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<input id="description" name="description" type="text" value="{{description}}">
<label for="goal-amount">Goal Amount</label>
<input id="goal-amount" name="amount" type="text" value="{{amount}}">
<label for="goal-due">Goal Due</label>
<input id="goal-due" name="due" type="text" value="{{due}}">
<label for="token">Token</label>
<input id="token" name="token" type="text" value="{{token}}">
<input type="submit" value="Save">
Expand Down