Add bible API
This commit is contained in:
@@ -128,6 +128,7 @@ userDB = (DB) => {
|
||||
let regEx = new RegExp(queryStr, 'i');
|
||||
let query = {
|
||||
isGroup: false,
|
||||
isChat: false,
|
||||
$or: [
|
||||
{"profile.firstName": {
|
||||
$regex: regEx
|
||||
@@ -140,7 +141,7 @@ userDB = (DB) => {
|
||||
}},
|
||||
]
|
||||
};
|
||||
let r = await DB.profileCols.find(queryStr ? query : {isGroup: false})
|
||||
let r = await DB.profileCols.find(queryStr ? query : {isGroup: false, isChat: false})
|
||||
.sort({ lastUpdate: -1 }).limit(20)
|
||||
.toArray().catch((err) => {
|
||||
console.log(err);
|
||||
@@ -166,7 +167,7 @@ userDB = (DB) => {
|
||||
return false;
|
||||
});
|
||||
let index = 0;
|
||||
while(r[index].isGroup) index += 1;
|
||||
while(r[index].isGroup || r[index].isChat) index += 1;
|
||||
if (r[index]) userProfileCache[r[index].id] = r[index];
|
||||
return r[index];
|
||||
}
|
||||
@@ -273,6 +274,7 @@ userDB = (DB) => {
|
||||
let query = {
|
||||
isGroup: true,
|
||||
isCourse: {$ne: true},
|
||||
isChat: {$ne: true},
|
||||
};
|
||||
if(excludePrivate) query.isPrivate = false;
|
||||
let r = await DB.profileCols.find(query).sort({ lastUpdate: -1 }).limit(10)
|
||||
@@ -289,13 +291,14 @@ userDB = (DB) => {
|
||||
for(id in profile.following){
|
||||
let oId = DB.ObjectID(id);
|
||||
let checkProfile = await DB.getProfileCache(oId)
|
||||
if(checkProfile && checkProfile.isGroup){
|
||||
if(checkProfile && checkProfile.isGroup && !checkProfile.isChat){
|
||||
ids.push(oId)
|
||||
}
|
||||
}
|
||||
let query = {
|
||||
isGroup: true,
|
||||
isCourse: {$ne: true},
|
||||
isChat: {$ne: true},
|
||||
_id: {
|
||||
$in: ids
|
||||
}
|
||||
@@ -312,6 +315,7 @@ userDB = (DB) => {
|
||||
let regEx = new RegExp(queryStr, 'i');
|
||||
let query = queryStr ? {
|
||||
isGroup: true,
|
||||
isChat: {$ne: true},
|
||||
isCourse: coursesB,
|
||||
$or: [
|
||||
{"profile.firstName": {
|
||||
@@ -327,7 +331,7 @@ userDB = (DB) => {
|
||||
$regex: regEx
|
||||
}}
|
||||
]
|
||||
} : {isGroup: true, isCourse: coursesB};
|
||||
} : {isGroup: true, isChat: {$ne: true}, isCourse: coursesB};
|
||||
let r = await DB.profileCols.find(query)
|
||||
.sort({ lastUpdate: -1 }).limit(20)
|
||||
.toArray().catch((err) => {
|
||||
@@ -353,7 +357,7 @@ userDB = (DB) => {
|
||||
DB.getGroup = async (groupid) => {
|
||||
const _id = DB.ObjectID(groupid);
|
||||
//if(userProfileCache[groupid]) return userProfileCache[groupid];
|
||||
let r = await DB.profileCols.findOne({_id, isGroup: true}).catch((err) => {
|
||||
let r = await DB.profileCols.findOne({_id, isGroup: true, isChat: {$ne: true},}).catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
@@ -425,7 +429,7 @@ userDB = (DB) => {
|
||||
|
||||
//Courses
|
||||
DB.getCourses = async () => {
|
||||
let r = await DB.profileCols.find({isGroup: true, isCourse: true})
|
||||
let r = await DB.profileCols.find({isGroup: true, isCourse: true, isChat: {$ne: true}})
|
||||
.sort({ lastUpdate: -1 }).limit(20)
|
||||
.toArray().catch((err) => {
|
||||
console.log(err);
|
||||
|
||||
@@ -16,6 +16,9 @@ class Post {
|
||||
this.lastUpdated = info.lastUpdated || this.createdAt;
|
||||
// Add tags to posts
|
||||
this.tags = info.tags;
|
||||
// For chats profileid will be the chat profile and the chatSenderId will be
|
||||
// the user sending the message, this will prevent showing on feed.
|
||||
this.chatSenderId = info.chatSenderId;
|
||||
}
|
||||
|
||||
addComment(comment){
|
||||
|
||||
@@ -22,9 +22,9 @@ class User {
|
||||
this.isGroup = info.isGroup || false;
|
||||
this.isCourse = info.isCourse || false;
|
||||
this.isPrivate = info.isPrivate || false;
|
||||
this.isChat = info.isChat || false;
|
||||
this.subscribed = info.subscribed || {}; //Subscribed user to groups
|
||||
this.pending = info.subscribed || {}; //Private groups require authorization
|
||||
|
||||
this.pending = info.pending || {}; //Private groups require authorization
|
||||
}
|
||||
|
||||
toObj(){
|
||||
@@ -42,6 +42,7 @@ class User {
|
||||
r.isGroup = this.isGroup;
|
||||
r.isCourse = this.isCourse;
|
||||
r.isPrivate = this.isPrivate;
|
||||
r.isChat = this.isChat;
|
||||
r.subscribed = this.subscribed;
|
||||
r.pending = this.pending;
|
||||
return r;
|
||||
|
||||
3
index.js
3
index.js
@@ -49,6 +49,7 @@ const profileRoute = require('./routes/profile.js');
|
||||
const postRoute = require('./routes/post.js');
|
||||
const paymentsRoute = require('./routes/payments.js');
|
||||
const subsplashRoute = require('./routes/subsplash.js');
|
||||
const bibleRoute = require('./routes/bible.js');
|
||||
|
||||
|
||||
DB.getDB.then((DB) => {
|
||||
@@ -256,9 +257,11 @@ DB.getDB.then((DB) => {
|
||||
app.use('/user', sessionChecker, profileRoute);
|
||||
app.use('/post', sessionChecker, postRoute);
|
||||
app.use('/payments', sessionChecker, paymentsRoute);
|
||||
app.use('/bible', sessionChecker, bibleRoute);
|
||||
|
||||
//Public Routes
|
||||
app.use('/subsplash', subsplashRoute);
|
||||
|
||||
|
||||
// route for handling 404 requests(unavailable routes)
|
||||
app.use(function (req, res, next) {
|
||||
|
||||
70
routes/bible.js
Normal file
70
routes/bible.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const axios = require('axios');
|
||||
var express = require('express')
|
||||
var router = express.Router()
|
||||
const DB = require("./../mongoDB.js");
|
||||
|
||||
const fetchAPI = async (path) => {
|
||||
baseUrl = "https://api.scripture.api.bible/v1/"
|
||||
let detailHtml = await axios.get(baseUrl + path, {headers:{'api-key':'8b43472a173a39e04cd868fd4848ed75'}}).catch(console.error);
|
||||
return detailHtml?.data;
|
||||
}
|
||||
|
||||
const defaultBibleId = "592420522e16049f-01";
|
||||
|
||||
//getMedia('y42zyf3').then(console.log)
|
||||
DB.getDB.then((DB) => {
|
||||
router.get("", async (req, res) => {
|
||||
const bibles = await fetchAPI('bibles');
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/books", async (req, res) => {
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId +"/books");
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/books", async (req, res) => {
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId +"/books");
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/books/:bookId", async (req, res) => {
|
||||
const bookId = req.params.bookId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId +"/books/" + bookId);
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/books/:bookId/chapters", async (req, res) => {
|
||||
const bookId = req.params.bookId;
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId +"/books/" + bookId + "/chapters");
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/chapters/:chapterId", async (req, res) => {
|
||||
const chapterId = req.params.chapterId;
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId + "/chapters/" + chapterId);
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/chapters/:chapterId/verses", async (req, res) => {
|
||||
const chapterId = req.params.chapterId;
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId + "/chapters/" + chapterId + "/verses");
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
router.get("/search", async (req, res) => {
|
||||
const query = req.query.query;
|
||||
const limit = req.query.limit || 10;
|
||||
const bibleId = req.query.bibleId || defaultBibleId;
|
||||
const bibles = await fetchAPI('bibles/' + bibleId + "/search?query=" + query + "&limit=" + limit);
|
||||
return res.json(bibles);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
module.exports = router
|
||||
Reference in New Issue
Block a user