Skip to content

Commit

Permalink
Merge pull request #5 from techla/21-tasks-add-edit
Browse files Browse the repository at this point in the history
adapting to front
  • Loading branch information
techla authored Mar 23, 2018
2 parents 8207831 + 221813d commit 5753bc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
20 changes: 11 additions & 9 deletions server/modules/tasks/server/controllers/tasks.server.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ exports.getAllTasks = function (req, res) {
orm.Task.findAll().then(function (tasks) {
res.status(200).send(tasks);
}).catch(function (error) {
console.log(error)
res.status(500).send(error);
});

Expand Down Expand Up @@ -42,27 +43,28 @@ exports.addTask = function (req, res) {
};

exports.updateTask = function (req, res) {

orm.Task.update(req.body, {
where: {
id: req.body.id
}
}).then(function (tasks) {
res.status(200).send(tasks);
orm.Task.update(
{ description: req.body.description, title: req.body.title },
{ where: { id: req.body.id }
}).then(function (task) {
res.status(200).send(req.body);
}).catch(function (error) {
console.log(error)
res.status(500).send(error);
});

};

exports.deleteTask = function (req, res) {

const taskId = req.params.id

orm.Task.destroy({
where: {
id: req.body.id
id: taskId
}
}).then(function (tasks) {
res.status(200).send(tasks);
res.status(200).send({ taskId });
}).catch(function (error) {
res.status(500).send(error);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ module.exports = function(sequelize, DataTypes) {
allowNull: false,
comment: 'The user who created and owns this task'
},
description: {
type: DataTypes.STRING,
allowNull: true,
comment: 'Some descriptions'
},
}, {
classMethods: {
associate: function (models) {
Expand Down
2 changes: 1 addition & 1 deletion server/modules/tasks/server/routes/tasks.server.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ module.exports = function (app) {
// CRUD actions
app.route('/api/tasks').post(tasks.validateSessionUser, tasks.addTask);
app.route('/api/tasks').put(tasks.validateSessionUser, tasks.updateTask);
app.route('/api/tasks').delete(tasks.validateSessionUser, tasks.deleteTask);
app.route('/api/tasks/:id').delete(tasks.validateSessionUser, tasks.deleteTask);

};

0 comments on commit 5753bc1

Please sign in to comment.