Created
February 6, 2017 15:43
-
-
Save zammitjames/33aa1f52b91d2d91e5461ddd2beb1d56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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