slugs created and implemented

This commit is contained in:
2020-01-07 14:23:44 -05:00
parent eb9d8f78f7
commit e69a1e03f8
6 changed files with 38 additions and 4 deletions

View File

@ -13,6 +13,7 @@ var Site = function(data){
this.unesco_unique = data.unesco_unique;
this.img_url = data.img_url
this.states = data.states;
this.slug = data.slug;
};
// Finding the site by ID.
@ -30,6 +31,21 @@ Site.findById = function(id, callback){
});
};
// Finding the site by slug.
Site.findBySlug = function(slug, callback){
var sql = "SELECT * FROM sites WHERE slug=? limit 1";
con.query(sql, slug, function(err, result){
if (err) return callback(err);
// if not site is found.
if (result[0] == undefined) callback(404);
else {
console.log("Site.findBySlug: " + result[0].site + " retrieved!");
callback(err, new Site(result[0]));
}
});
};
// Finding all sites by IDs.
Site.findAllById = function(ids, callback){
var sql = "SELECT * FROM sites WHERE id in (?)";