From 2d7c6d2fbb933c71c4099c0ff476f8fdc74d558f Mon Sep 17 00:00:00 2001 From: Adam Lofting Date: Fri, 4 Apr 2014 15:36:08 +0100 Subject: [PATCH] delete your own data (to enable testing) --- lib/data.js | 33 +++++++++++++++++++++++++++++++++ tasks.todo | 3 ++- views/log-em.handlebars | 3 +++ web.js | 16 +++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/data.js b/lib/data.js index 767cd25..02dae91 100644 --- a/lib/data.js +++ b/lib/data.js @@ -161,3 +161,36 @@ exports.saveItem = function saveItem(entry, callback) { } }); }; + +/** + * Delete an activity from the DB + * @param {field object} toDelete + * @param {Function} callback + * @return {null} + */ +exports.deleteItem = function saveItem(toDelete, callback) { + pool.getConnection(function (err, connection) { + + if (err) { + console.error(err); + callback(err); + + } else { + + var target = "logged_by=" + connection.escape(toDelete.logged_by) + " AND "; + target = target + "contributor_id=" + connection.escape(toDelete.contributor_id) + " AND "; + target = target + "contribution_date=" + connection.escape(toDelete.contribution_date) + " AND "; + target = target + "mofo_team=" + connection.escape(toDelete.mofo_team) + " AND "; + target = target + "data_bucket=" + connection.escape(toDelete.data_bucket); + + connection.query('DELETE FROM contributions WHERE ' + target, function (err, result) { + if (err) { + console.error(err); + callback(err); + } + connection.release(); + callback(null); + }); + } + }); +}; diff --git a/tasks.todo b/tasks.todo index 7d7b35f..c117fdf 100644 --- a/tasks.todo +++ b/tasks.todo @@ -1,9 +1,10 @@ MVP: - ☐ sample .env Nice to have: ___________________ Archive: + ✔ Delete recent entry option (only applies to self) @done (14-04-04 15:35) + ✔ sample .env @done (14-04-04 14:52) ✔ enforce SSL on heroku @done (14-04-04 14:34) ✔ Remember users team etc. @done (14-04-04 14:06) @project(Nice to have) ✔ Date picker @done (14-04-04 13:49) @project(Nice to have) diff --git a/views/log-em.handlebars b/views/log-em.handlebars index 305937b..7d906f4 100644 --- a/views/log-em.handlebars +++ b/views/log-em.handlebars @@ -52,12 +52,15 @@ Team Type Description +   {{#each recentlyLogged}} {{#each this}} {{this}} {{/each}} + + {{/each}} diff --git a/web.js b/web.js index 4fd2341..14a53a0 100644 --- a/web.js +++ b/web.js @@ -55,7 +55,7 @@ require("express-persona")(app, { }); return; } - + console.log("Login attempt by: ", req.session.email); res.json({ status: "failure", reason: "Only users with a mozillafoundation.org email address may use this tool" @@ -109,6 +109,20 @@ app.post('/log-em', restrict, function (req, res) { }); }); +app.get('/delete', restrict, function (req, res) { + var toDelete = { + logged_by: req.session.email, + contributor_id: req.query.contributor_id, + contribution_date: req.query.contribution_date, + mofo_team: req.query.mofo_team, + data_bucket: req.query.data_bucket + }; + data.deleteItem(toDelete, function deletedItem(err, response) { + console.log("deleted", req.session.email); + res.redirect('/log-em#logged'); + }); +}); + app.get('/api', function (req, res) { var date = null; var team = null;