Added User Avatar to note response

This commit is contained in:
Sagi Dayan 2016-07-03 14:25:47 +03:00
parent 06dd2978b1
commit b2808ef65e
2 changed files with 45 additions and 33 deletions

View file

@ -57,6 +57,17 @@ router.post('/upsert', (req, res) => {
} }
}); });
} else { //** Create a new Note **// } else { //** Create a new Note **//
var key = db.key(['User', Number(req.body.owner_id)]);
db.get(key, (err, entity) => {
if (err) {
utils.response_500(res, "DB Error");
return;
}
if (!entity) {
utils.response_400(res, null, "No User with that id!");
return;
}
var user = utils.convertToUserObj(entity);
db.save({ db.save({
key: db.key('Note'), key: db.key('Note'),
data: { data: {
@ -70,6 +81,7 @@ router.post('/upsert', (req, res) => {
created_at: Date.now(), created_at: Date.now(),
likes: 0, likes: 0,
tags: req.body.tags || [], tags: req.body.tags || [],
avatar: user.avatar
} }
}, },
(err, response) => { (err, response) => {
@ -87,7 +99,7 @@ router.post('/upsert', (req, res) => {
else utils.response_500(res, "DB Error->" + err); else utils.response_500(res, "DB Error->" + err);
}); });
} }
});
}); });
} }
} }

View file

@ -43,8 +43,8 @@ module.exports = {
is_public: note.data.is_public, is_public: note.data.is_public,
created_at: note.data.created_at, created_at: note.data.created_at,
likes: note.data.likes, likes: note.data.likes,
tags: note.data.tags tags: note.data.tags,
avatar: note.data.avatar
}; };
} }
}; };