Browse Source

Refactored and documented newly written code.

pull/34/head
jrtechs 6 years ago
parent
commit
d683d6a8e5
4 changed files with 33 additions and 17 deletions
  1. +5
    -7
      posts/category.js
  2. +3
    -6
      posts/posts.js
  3. +6
    -4
      posts/renderBatchOfPreviewes.js
  4. +19
    -0
      posts/renderNextBar.js

+ 5
- 7
posts/category.js View File

@ -1,12 +1,9 @@
//DB query
/** DB query */
const sql = require('../utils/sql');
//file IO
const utils = require('../utils/utils.js');
/** Object used to render blog post previews */
const batchPreview = require('../posts/renderBatchOfPreviewes');
/**
* Renders all posts in a single category
*
@ -40,8 +37,9 @@ module.exports=
/**
* Calls posts and sidebar modules to render blog contents in order
*
* @param res
* @param fileName request url
* @param requestURL
* @param request
* @returns {Promise}
*/
main: function(requestURL, request)
{

+ 3
- 6
posts/posts.js View File

@ -1,7 +1,4 @@
//file io
const utils = require('../utils/utils.js');
//DB queries
/** DB queries */
const sql = require('../utils/sql');
@ -9,7 +6,6 @@ const sql = require('../utils/sql');
* Function responsible for calling the appropriate sql requests to query
* database and serve correct blog post
*
* @param res the result sent to the client
* @param requestURL url requested from client
* @return {*|Promise} returns a resolved promise to preserve execution order
*/
@ -59,7 +55,8 @@ module.exports=
{
return new Promise(function(resolve, reject)
{
Promise.all([renderPost(requestURL), require("../sidebar/sidebar.js").main()]).then(function(content)
Promise.all([renderPost(requestURL),
require("../sidebar/sidebar.js").main()]).then(function(content)
{
resolve(content.join(''));
}).catch(function(error)

+ 6
- 4
posts/renderBatchOfPreviewes.js View File

@ -1,11 +1,13 @@
module.exports=
{
/**
* Calls posts and sidebar modules to render blog contents in order
* Renders a bunch of blog post previews to the user
*
* @param res
* @param fileName request url
* @param baseURL-- url of the page
* @param posts -- sql data about the posts to render
* @param currentPage -- the current page to render
* @param numOfPosts -- number of posts to render
* @returns {Promise} renders the html of the posts
*/
main: function(baseURL, posts, currentPage, numOfPosts)
{

+ 19
- 0
posts/renderNextBar.js View File

@ -1,3 +1,11 @@
/**
* Determines if the requested page is out of bounds
*
* @param page current page
* @param postsPerPage - number of posts rendered on each page
* @param totalPosts - total posts in this category/total
* @returns {boolean} if this is a valid page
*/
const isValidPage = function(page, postsPerPage, totalPosts)
{
return !(page === 0 || page -1 >= totalPosts/postsPerPage);
@ -5,6 +13,17 @@ const isValidPage = function(page, postsPerPage, totalPosts)
module.exports=
{
/**
* Renders two buttons on the bottom of the page to
* go to the left or right
*
* Used by the home page and categories pages
* @param baseURL -- base url of page being rendered
* @param currentPage -- current page being rendered
* @param postsPerPage -- number of posts on each page
* @param totalPosts -- total amount of posts in the category
* @returns {Promise} promise which renders the buttons
*/
main: function(baseURL, currentPage, postsPerPage, totalPosts)
{
return new Promise(function(resolve, reject)

Loading…
Cancel
Save