Browse Source

Merge pull request #99 from jrtechs/more_posts

More posts -- Added API Routes
pull/101/head
Jeffery Russell 4 years ago
committed by GitHub
parent
commit
275a5e7a26
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 0 deletions
  1. +24
    -0
      routes/api/index.js

+ 24
- 0
routes/api/index.js View File

@ -3,6 +3,30 @@ const sql = require('../../utils/sql');
const renderPost = require('../../blog/renderBlogPost');
routes.get('/getPostsIds/:category', (request, result) =>
{
if(request.params.category.length !== 1 &&
request.params.category.length !== 2)
{
result.json("boo").end();
return;
}
sql.getPostIds(request.params.category).then((sqlData)=>
{
var arr = [];
for(var i = 5; i < sqlData.length; i++)
{
arr.push(sqlData[i].post_id)
}
result.json(arr).end();
}).catch((err)=>
{
result.status(404).json({error: 404}).end();
})
});
routes.get('/posts', (request, result) =>
{
sql.getAllPosts().then((data)=>

Loading…
Cancel
Save