Skip to content

Instantly share code, notes, and snippets.

@zammitjames
Created February 6, 2017 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zammitjames/33aa1f52b91d2d91e5461ddd2beb1d56 to your computer and use it in GitHub Desktop.
Save zammitjames/33aa1f52b91d2d91e5461ddd2beb1d56 to your computer and use it in GitHub Desktop.
app.get("/k/listings/:name", function(req, res){
var id = req.url.replace("/k/listings/", "");
console.log(id);
db.ref("pre_processed_listings/"+id).once("value",function(snapshot) {
if (snapshot.val() != null) {
db.ref("pre_processed_listings/"+id+"/_state").set("in_progress");
db.ref("listings/"+id).set(snapshot.val()).then(function() {
// Add listing to User Data
db.ref("additional/user_data/"+snapshot.val().author_id+"/associated_listings/"+id).set(true);
// Add Listing to Tags Data
var listener_listings = db.ref("listings/"+id+"/tags");
listener_listings.on("child_added",function (tags) {
db.ref("additional/tags_data/"+tags.val()+"/"+id).set(true);
});
listener_listings.once("value",function (tags) {
listener_listings.off();
});
// Add Listing to Category Data
db.ref("additional/category_data/"+snapshot.val().category_id+"/listings/"+id).set(true).then(function(){
db.ref("pre_processed_listings/"+id).remove();
});
});
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment