Added User/Upsert
This commit is contained in:
parent
f26625b469
commit
d0a9eaf9e2
1 changed files with 36 additions and 2 deletions
|
@ -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)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue