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); },