vargetCategory="select url from categories where "+
"category_id='"+post.category_id+"'";
fetch(getCategory).then(function(urls)
{
varobj=newObject();
obj.name=post.name;
obj.url=post.url;
obj.published=post.published;
obj.category=urls[0].url;
res(obj);
});
}));
});
Promise.all(promises).then(function(goodies)
{
resolve(goodies);
});
});
};
module.exports=
{
/**
@ -180,31 +142,9 @@ module.exports=
getPostIds:function(categoryID)
{
returnnewPromise((resolve,reject)=>
{
if(categoryID==0)
{
fetch("select post_id from posts order by published desc")
.then(function(ids)
{
resolve(ids);
}).catch((error)=>
{
reject(error);
});
}
else
{
fetch("select post_id from posts where category_id='"+categoryID+"' order by published desc")
.then(function(ids)
{
resolve(ids);
}).catch((error)=>
{
reject(error);
});
}
});
varq=categoryID==0?"select post_id from posts order by published desc":
"select post_id from posts where category_id='"+categoryID+"' order by published desc";
returnfetch(q);
},
insert:function(sqlStatement)
@ -268,23 +208,8 @@ module.exports=
*/
getPostsFromCategory:function(requestURL)
{
returnnewPromise(function(resolve,reject)
{
varq="select * from categories where url ='"+requestURL+"'";
fetch(q).then(function(categories)
{
if(categories.length!=0)
{
varqPosts="select * from posts where category_id='"+
categories[0].category_id+"' order by published desc";
resolve(fetch(qPosts));
}
else
{
resolve([]);
}
});
});
varq="SELECT posts.post_id, posts.pinned, posts.name, posts.url, posts.category_id, posts.published, posts.picture_url FROM categories INNER JOIN posts on categories.category_id=posts.category_id and categories.url='"+requestURL+"' order by posts.published desc";
returnfetch(q);
},
@ -308,18 +233,9 @@ module.exports=
getRecentPosts:function(limit)
{
limit=(limit==null)?10:limit;
returnnewPromise(function(resolve,reject)
{
varq="select name,url, published, category_id from posts order "+
varq="select posts.name, posts.url, posts.published, posts.category_id, categories.url as category from posts INNER JOIN categories on posts.category_id=categories.category_id order "+
"by post_id desc limit "+limit;
returnfetch(q);
},
@ -330,18 +246,7 @@ module.exports=
*/
getPinnedPosts:function()
{
returnnewPromise(function(resolve,reject)
{
varq="select name,url, category_id from posts where pinned=1 order "+
returnfetch("select posts.name, posts.url, posts.category_id, categories.url as category from posts INNER JOIN categories on posts.category_id=categories.category_id where pinned=1 order by post_id desc");