Browse Source

Updated the way which posts are displayed in the category pages

pull/4/head
Jeffery R 6 years ago
parent
commit
f1a2fc3732
1 changed files with 16 additions and 10 deletions
  1. +16
    -10
      utils/sql.js

+ 16
- 10
utils/sql.js View File

@ -88,7 +88,8 @@ module.exports=
if(result_category.length != 0) if(result_category.length != 0)
{ {
var q2 = "select * from posts where category_id='" + result_category[0].category_id +
var q2 = "select * from posts where category_id='" +
result_category[0].category_id +
"' and url='" + splitURL[2] + "'"; "' and url='" + splitURL[2] + "'";
fetch(q2).then(function (result_posts) fetch(q2).then(function (result_posts)
@ -124,7 +125,8 @@ module.exports=
}, },
/** /**
* Function which currently returns all posts of a particular category from the database
* Function which currently returns all posts of a particular
* category from the database
* @param requestURL * @param requestURL
* @return {*|Promise} * @return {*|Promise}
*/ */
@ -137,7 +139,8 @@ module.exports=
{ {
if(categories.length != 0) if(categories.length != 0)
{ {
var qPosts = "select * from posts where category_id='" + categories[0].category_id + "'";
var qPosts = "select * from posts where category_id='" +
categories[0].category_id + "' order by published desc";
resolve(fetch(qPosts)); resolve(fetch(qPosts));
} }
else else
@ -149,7 +152,8 @@ module.exports=
}, },
/** /**
* Helper method which returns a list of objects which contains the url and name of thee ten most recent posts
* Helper method which returns a list of objects which contains the url
* and name of thee ten most recent posts
* *
* {[name: , url: ],[name: , url: ],[name: , url: ],...} * {[name: , url: ],[name: , url: ],[name: , url: ],...}
* *
@ -159,7 +163,8 @@ module.exports=
{ {
return new Promise(function(resolve, reject) return new Promise(function(resolve, reject)
{ {
var q = "select name,url, category_id from posts order by post_id desc limit 10";
var q = "select name,url, category_id from posts order " +
"by post_id desc limit 10";
fetch(q).then(function(sqlPosts) fetch(q).then(function(sqlPosts)
{ {
var promises = []; var promises = [];
@ -167,7 +172,8 @@ module.exports=
{ {
promises.push(new Promise(function(res, rej) promises.push(new Promise(function(res, rej)
{ {
var getCategory = "select url from categories where category_id='" + post.category_id + "'";
var getCategory = "select url from categories where " +
"category_id='" + post.category_id + "'";
fetch(getCategory).then(function(urls) fetch(getCategory).then(function(urls)
{ {
var obj = new Object(); var obj = new Object();
@ -218,7 +224,8 @@ module.exports=
var cleanName = sanitizer.sanitize(post.username); var cleanName = sanitizer.sanitize(post.username);
var cleanPassword = sanitizer.sanitize(post.password); var cleanPassword = sanitizer.sanitize(post.password);
var getSalt = "select * from users where user_name='" + cleanName + "'";
var getSalt = "select * from users where user_name='" +
cleanName + "'";
fetch(getSalt).then(function(saltResult) fetch(getSalt).then(function(saltResult)
{ {
if(saltResult.length == 1) if(saltResult.length == 1)
@ -228,14 +235,12 @@ module.exports=
.digest('hex'); .digest('hex');
if(saltResult[0].password === hashedPassword) if(saltResult[0].password === hashedPassword)
{ {
//yay!
result.pass = true; result.pass = true;
result.user = cleanName; result.user = cleanName;
resolve(result); resolve(result);
} }
else else
{ {
//wrong password
resolve(result) resolve(result)
} }
} }
@ -256,7 +261,8 @@ module.exports=
getCategory: function(categoryId) getCategory: function(categoryId)
{ {
return fetch("select * from categories where category_id='" + categoryId + "'");
return fetch("select * from categories where category_id='"
+ categoryId + "'");
}, },
getDownload: function(downloadURL) getDownload: function(downloadURL)

Loading…
Cancel
Save