Skip to content

Commit

Permalink
adding surah info in ayah
Browse files Browse the repository at this point in the history
  • Loading branch information
AxeemHaider committed Mar 18, 2021
1 parent f195715 commit 984815b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Install require packages

Move into firebase dir

`cd quran-api/firebase`
`cd quran-api/firebase` This is not upto date

`cd ../hadith-api/firebase`

Run local Firestore

Expand Down
2 changes: 1 addition & 1 deletion src/api-v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ router.get("/welcome", welcomeEveryone);
router.get("/ayah/:id", getSingleAyah.byId);
router.get("/ayah/number/:number", getSingleAyah.byNumber);

router.get("/surah/:number?", getSurah);
router.get("/surah/list", getSurahList);
router.get("/surah/:number?", getSurah);

module.exports = router;
16 changes: 14 additions & 2 deletions src/api-v1/routes/getSingleAyah.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
const Ayah = require("../models/Ayah");
const surah_list = require("./surah_list");

const byId = async (req, res, next) => {
try {
const ayah = await Ayah.collection.get({ id: req.params.id });
return res.status(200).json(ayah.toObject());

const surah = surah_list[ayah.surah_number - 1];

return res.status(200).json({
surah: surah,
ayah: ayah.toObject(),
});
} catch (err) {
next(err);
}
Expand All @@ -14,7 +21,12 @@ const byNumber = async (req, res, next) => {
const number = parseInt(req.params.number);
const ayah = await Ayah.collection.where("number", "==", number).get();

return res.status(200).json(ayah.toObject());
const surah = surah_list[ayah.surah_number - 1];

return res.status(200).json({
surah: surah,
ayah: ayah.toObject(),
});
} catch (err) {
next(err);
}
Expand Down
4 changes: 4 additions & 0 deletions src/api-v1/routes/getSurah.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Ayah = require("../models/Ayah");
const surah_list = require("./surah_list");

const getSurah = async (req, res, next) => {
try {
Expand Down Expand Up @@ -44,8 +45,11 @@ const getSurah = async (req, res, next) => {
ayahList.push(ayah.toObject());
}

const surah = surah_list[ayahList[0].surah_number - 1];

res.status(200).json({
cursor: snapShot.cursor,
surah: surah,
ayahs: ayahList,
});
} catch (err) {
Expand Down

0 comments on commit 984815b

Please sign in to comment.