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 **//
|
} else { //** Create a new Note **//
|
||||||
db.save({
|
var key = db.key(['User', Number(req.body.owner_id)]);
|
||||||
key: db.key('Note'),
|
db.get(key, (err, entity) => {
|
||||||
data: {
|
if (err) {
|
||||||
title: req.body.title,
|
utils.response_500(res, "DB Error");
|
||||||
lat: req.body.lat,
|
return;
|
||||||
lng: req.body.lng,
|
}
|
||||||
address: req.body.address,
|
if (!entity) {
|
||||||
body: req.body.body,
|
utils.response_400(res, null, "No User with that id!");
|
||||||
owner_id: req.body.owner_id,
|
return;
|
||||||
is_public: req.body.is_public || false,
|
}
|
||||||
created_at: Date.now(),
|
var user = utils.convertToUserObj(entity);
|
||||||
likes: 0,
|
db.save({
|
||||||
tags: req.body.tags || [],
|
key: db.key('Note'),
|
||||||
}
|
data: {
|
||||||
},
|
title: req.body.title,
|
||||||
(err, response) => {
|
lat: req.body.lat,
|
||||||
if (err) {
|
lng: req.body.lng,
|
||||||
utils.response_500(res, "DB Error");
|
address: req.body.address,
|
||||||
} else {
|
body: req.body.body,
|
||||||
res.statusCode = 201;
|
owner_id: req.body.owner_id,
|
||||||
var id = Number(response.mutationResults[0].key.path[0].id);
|
is_public: req.body.is_public || false,
|
||||||
var key = db.key(['Note', id]);
|
created_at: Date.now(),
|
||||||
db.get(key, (err, entity) => {
|
likes: 0,
|
||||||
if (!err) res.send({
|
tags: req.body.tags || [],
|
||||||
status: "OK",
|
avatar: user.avatar
|
||||||
note: utils.convertToNoteObj(entity)
|
}
|
||||||
|
},
|
||||||
|
(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,
|
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
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue