From 984815b02de2d84c549d2d21e1074096553a9a60 Mon Sep 17 00:00:00 2001 From: axeemhaider Date: Thu, 18 Mar 2021 09:37:24 +0500 Subject: [PATCH] adding surah info in ayah --- README.md | 4 +++- src/api-v1/index.js | 2 +- src/api-v1/routes/getSingleAyah.js | 16 ++++++++++++++-- src/api-v1/routes/getSurah.js | 4 ++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1489465..d60ef02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/api-v1/index.js b/src/api-v1/index.js index e443a74..d7e39b4 100644 --- a/src/api-v1/index.js +++ b/src/api-v1/index.js @@ -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; diff --git a/src/api-v1/routes/getSingleAyah.js b/src/api-v1/routes/getSingleAyah.js index 495dced..b98855b 100644 --- a/src/api-v1/routes/getSingleAyah.js +++ b/src/api-v1/routes/getSingleAyah.js @@ -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); } @@ -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); } diff --git a/src/api-v1/routes/getSurah.js b/src/api-v1/routes/getSurah.js index d6e943e..5fc8873 100644 --- a/src/api-v1/routes/getSurah.js +++ b/src/api-v1/routes/getSurah.js @@ -1,4 +1,5 @@ const Ayah = require("../models/Ayah"); +const surah_list = require("./surah_list"); const getSurah = async (req, res, next) => { try { @@ -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) {