Added User Avatar to note response
This commit is contained in:
parent
06dd2978b1
commit
b2808ef65e
2 changed files with 45 additions and 33 deletions
|
@ -57,38 +57,50 @@ router.post('/upsert', (req, res) => {
|
|||
}
|
||||
});
|
||||
} else { //** Create a new Note **//
|
||||
db.save({
|
||||
key: db.key('Note'),
|
||||
data: {
|
||||
title: req.body.title,
|
||||
lat: req.body.lat,
|
||||
lng: req.body.lng,
|
||||
address: req.body.address,
|
||||
body: req.body.body,
|
||||
owner_id: req.body.owner_id,
|
||||
is_public: req.body.is_public || false,
|
||||
created_at: Date.now(),
|
||||
likes: 0,
|
||||
tags: req.body.tags || [],
|
||||
}
|
||||
},
|
||||
(err, response) => {
|
||||
if (err) {
|
||||
utils.response_500(res, "DB Error");
|
||||
} else {
|
||||
res.statusCode = 201;
|
||||
var id = Number(response.mutationResults[0].key.path[0].id);
|
||||
var key = db.key(['Note', id]);
|
||||
db.get(key, (err, entity) => {
|
||||
if (!err) res.send({
|
||||
status: "OK",
|
||||
note: utils.convertToNoteObj(entity)
|
||||
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({
|
||||
key: db.key('Note'),
|
||||
data: {
|
||||
title: req.body.title,
|
||||
lat: req.body.lat,
|
||||
lng: req.body.lng,
|
||||
address: req.body.address,
|
||||
body: req.body.body,
|
||||
owner_id: req.body.owner_id,
|
||||
is_public: req.body.is_public || false,
|
||||
created_at: Date.now(),
|
||||
likes: 0,
|
||||
tags: req.body.tags || [],
|
||||
avatar: user.avatar
|
||||
}
|
||||
},
|
||||
(err, response) => {
|
||||
if (err) {
|
||||
utils.response_500(res, "DB Error");
|
||||
} else {
|
||||
res.statusCode = 201;
|
||||
var id = Number(response.mutationResults[0].key.path[0].id);
|
||||
var key = db.key(['Note', id]);
|
||||
db.get(key, (err, entity) => {
|
||||
if (!err) res.send({
|
||||
status: "OK",
|
||||
note: utils.convertToNoteObj(entity)
|
||||
});
|
||||
else utils.response_500(res, "DB Error->" + err);
|
||||
});
|
||||
else utils.response_500(res, "DB Error->" + err);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -43,8 +43,8 @@ module.exports = {
|
|||
is_public: note.data.is_public,
|
||||
created_at: note.data.created_at,
|
||||
likes: note.data.likes,
|
||||
tags: note.data.tags
|
||||
tags: note.data.tags,
|
||||
avatar: note.data.avatar
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue