Skip to content

Commit

Permalink
Fix task creation. Empty form fields after submit.
Browse files Browse the repository at this point in the history
  • Loading branch information
gleblobanov committed Jun 29, 2015
1 parent 79ab696 commit 1d7b1e9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
10 changes: 9 additions & 1 deletion client/public/javascripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ angular.module('nodeTodo', ['ngMaterial', 'datePicker', 'infinite-scroll'])


$scope.createTodo = function () {

$scope.formData.complete = false;

$http.post('/api/v1/todos/',$scope.formData)
.success(function (data) {
fillTodoData(data);
data.forEach(function (item)
{
$scope.todoAll.unshift(item);
$scope.formData.text = '';
$scope.formData.date = '';
})
})
.error(function (error) {
})
Expand All @@ -47,6 +54,7 @@ angular.module('nodeTodo', ['ngMaterial', 'datePicker', 'infinite-scroll'])

$http.post('/api/v1/todos/complete/', { id: todoID, new_value: complete } )
.success(function (data) {

})
.error(function () {
})
Expand Down
24 changes: 13 additions & 11 deletions server/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ router.post('/api/v1/todos', function(req, res) {
var data = {text: req.body.text, complete: req.body.complete, date: req.body.date};

pg.connect(connectionString, function(err, client, done) {
client.query("INSERT INTO items (text, complete, date) VALUES ($1, $2, $3)", [data.text, data.complete, data.date]);
var query = client.query("SELECT * FROM items ORDER BY id ASC");

query.on('row', function(row) {
results.push(row);
});

query.on('end', function () {
client.end();
return res.json(results);
});
client.query("INSERT INTO items (text, complete, date) VALUES ($1, $2, $3) RETURNING id", [data.text, data.complete, data.date],
function (err, result1) {
if (err) {

} else {
client.query("SELECT * FROM items WHERE id = ($1)", [result1.rows[0].id], function (err, result2) {
results.push(result2.rows[0]);
client.end();
return res.json(results);
});

}
});

if (err) {
console.log(err);
Expand Down

0 comments on commit 1d7b1e9

Please sign in to comment.