diff --git a/server/api.js b/server/api.js index e06af54..2e5a871 100644 --- a/server/api.js +++ b/server/api.js @@ -83,7 +83,38 @@ router.post('/register', (req, res) => { } }); -router.post('/user/upsert', (req, res) => {}); +router.post('/user/upsert', (req, res) => { + if (!req.body || !req.body.id) { + utils.response_400(res, { + username: "JhonSnow", + password: "TheKingOfTheN0rth_65bc", + email: "jhon@nights_watch.com", + avatar: "path/to/avatar", + id: 123 + }); + } else { + var key = db.key(['User', Number(req.body.id)]); + db.get(key, (err, entity) => { + if (err) { + utils.response_500(res, "DB Error"); + } else { + entity.data.email = req.body.email || entity.data.email; + entity.data.avatar = req.body.avatar || entity.data.avatar; + entity.data.password = req.body.password || entity.data.password; + db.save(entity, (err, _resp) => { + if (err) { + utils.response_500(res, "DB Error"); + } else { + res.send({ + status: "OK", + user: utils.convertToUserObj(entity) + }); + } + }); + } + }); + } +}); router.post('/note/upsert', (req, res) => { if (!req.body || !req.body.title || !req.body.body || !req.body.owner_id || !req.body.address) { utils.response_400(res, { @@ -126,7 +157,10 @@ router.post('/note/upsert', (req, res) => { if (err) { utils.response_500(res, "DB Error"); } else { - res.send(utils.convertToNoteObj(entity)); + res.send({ + status: "OK", + note: utils.convertToNoteObj(entity) + }); } });