Added User/Upsert

This commit is contained in:
Sagi Dayan 2016-07-02 15:01:23 +03:00
parent f26625b469
commit d0a9eaf9e2

View file

@ -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) => { router.post('/note/upsert', (req, res) => {
if (!req.body || !req.body.title || !req.body.body || !req.body.owner_id || !req.body.address) { if (!req.body || !req.body.title || !req.body.body || !req.body.owner_id || !req.body.address) {
utils.response_400(res, { utils.response_400(res, {
@ -126,7 +157,10 @@ router.post('/note/upsert', (req, res) => {
if (err) { if (err) {
utils.response_500(res, "DB Error"); utils.response_500(res, "DB Error");
} else { } else {
res.send(utils.convertToNoteObj(entity)); res.send({
status: "OK",
note: utils.convertToNoteObj(entity)
});
} }
}); });