Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anwarulislam committed May 15, 2019
0 parents commit 8e647b3
Show file tree
Hide file tree
Showing 17 changed files with 17,945 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PORT=4200
DB_URI=mongodb://localhost:27017/quran
SECRET=alksdjflajldkfjlakdflkj
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
5 changes: 5 additions & 0 deletions controllers/noteConroller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Note = require('./../models/Note')

module.exports.addNote = (req, res) => {
res.json(req.body)
}
40 changes: 40 additions & 0 deletions controllers/surahController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Surah = require('./../models/Surah')

module.exports.getAllSurah = async (req, res) => {
var fs = require('fs');

// fs.readFile('./../surah.json', function (err, data) {
// if (err) throw err;

// console.log(data);
// })

const surah = require('./../surah.json')

res.json(surah)
}

module.exports.getSurah = async (req, res) => {
const options = {
page: req.query.p || 1,
limit: 10,
customLabels: 'hlaksdjf'
};
let surah = await Surah.paginate({ sura: req.params.surah_no }, options, 5, (error, pageCount, paginatedResults) => {
if (error) {
console.error(error);
} else {
console.log('Pages:', pageCount);
console.log(paginatedResults);
}
})

if (surah.prevPage) {
surah.prevLink = req.protocol + '://' + req.get('host') + req.path + `?p=${surah.prevPage}`
}
if (surah.nextPage) {
surah.nextLink = req.protocol + '://' + req.get('host') + req.path + `?p=${surah.nextPage}`
}

res.json(surah)
}
11 changes: 11 additions & 0 deletions dbconnect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//Import mongoose library
const mongoose = require('mongoose');

//connect db
mongoose.connect(process.env.DB_URI, { useNewUrlParser: true })
.then(res => {
console.log('database connected')
})
.catch(err => {
console.log('database disconnected')
})
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const express = require('express')
const app = express()
const expressSession = require('express-session')
const cookieParser = require('cookie-parser')

require('dotenv').config()
require('./dbconnect')

app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(expressSession({
secret: process.env.SECRET,
resave: true,
saveUninitialized: true
}))
app.use(cookieParser())

app.listen(process.env.PORT, () => {
console.log(`Server is running at http://localhost:${process.env.PORT}`);
})

app.use(express.static(__dirname + '/public'))

const quranRouter = require('./routes/quran')
const noteRouter = require('./routes/note')
app.use(quranRouter)
app.use('/note', noteRouter)
11 changes: 11 additions & 0 deletions models/Note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const mongoose = require('mongoose')

let suraScheema = mongoose.Schema(
{
sura: String,
ayah: String,
text: String
}
)

module.exports = mongoose.model('Notes', suraScheema)
15 changes: 15 additions & 0 deletions models/Surah.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const mongoose = require('mongoose')
var mongoosePaginate = require('mongoose-paginate-v2');

let suraScheema = mongoose.Schema(
{
sura: String,
ayah: String,
text: String,
doc_id: String,
primary: String
}
)
suraScheema.plugin(mongoosePaginate);

module.exports = mongoose.model('Ayah', suraScheema, 'ayah')
Loading

0 comments on commit 8e647b3

Please sign in to comment.