From 06dd2978b1a5a5bac190292e395f3958393c65e9 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 3 Jul 2016 13:38:29 +0300 Subject: [PATCH] Added Note Deletion --- server/noteRouter.js | 30 +++++++++++++++++++++++++++++- server/utils.js | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/server/noteRouter.js b/server/noteRouter.js index 1636d94..2968763 100644 --- a/server/noteRouter.js +++ b/server/noteRouter.js @@ -157,7 +157,7 @@ router.post('/like', (req, res) => { } }); -router.post('/stream', (req, res) => { +router.post('/getPublic', (req, res) => { if (!req.body.id) { utils.response_400(res, { id: 123, @@ -224,6 +224,34 @@ router.post('/stream', (req, res) => { } }); +router.post('/delete', (req, res) => { + if (!req.body.uid || !req.body.nid) { + utils.response_400(res, { + uid: 123, + nid: 123 + }); + return; + } + var key = db.key(['Note', Number(req.body.nid)]); + db.get(key, (err, entity) => { + if (!entity || Number(utils.convertToNoteObj(entity) + .owner_id) != Number(req.body.uid)) { + utils.response_400(res, null, "The Note not exists OR he is not the owner of the note"); + return; + } + db.delete(key, (err, apiResp) => { + if (!err) { + res.send({ + status: "OK", + message: "Note Deleted" + }); + return; + } + utils.response_500(res, "Error while Deleting Note"); + }); + }); +}); + module.exports = router; diff --git a/server/utils.js b/server/utils.js index 9c40f52..947eef3 100644 --- a/server/utils.js +++ b/server/utils.js @@ -5,7 +5,7 @@ module.exports = { example_body: example, status: 'Error', code: 400, - message: 'Bad request, ' + msg || 'see the example for more information' + message: 'Bad request, ' + (msg || 'see the example for more information') }; res.send(r); },