Ayat Range Test

This commit is contained in:
Otang45
2024-05-23 02:58:48 +07:00
parent a3c5363299
commit 0f93ba721f
6 changed files with 268 additions and 96 deletions

View File

@@ -25,6 +25,10 @@ const getAyah = (req, res) => {
const { surahId, ayahId } = req.params;
res.send({ data: quranService.getAyah(surahId, ayahId) });
};
const getAyahRange = (req, res) => {
const { surahId, startId, endId } = req.params;
res.send({ data: quranService.getAyahRange(surahId, startId, endId) });
};
const getAyahJuz = (req, res) => {
const { juzId } = req.params;
res.send({ data: quranService.getAyahJuz(juzId) });
@@ -76,6 +80,7 @@ module.exports = {
getJuz,
getAyahSurah,
getAyah,
getAyahRange,
getAyahJuz,
getAllAyah,
getAyahPage,

View File

@@ -40,6 +40,15 @@ const getAyah = (surahId, ayahId) => {
}
return result;
};
const getAyahRange = (surahId, startId, endId) => {
var result = [];
for (let index = 0; index < ayah.length; index++) {
if (ayah[index].surah == surahId) {
result.push(ayah[index]);
}
}
return result.slice(startId - 1, endId - 1);
};
const getAyahJuz = (juzId) => {
var result = [];
for (let index = 0; index < ayah.length; index++) {
@@ -129,6 +138,7 @@ module.exports = {
getJuz,
getAyahSurah,
getAyah,
getAyahRange,
getAyahJuz,
getAllAyah,
getAyahPage,

View File

@@ -53,6 +53,10 @@ router.get("/", (req, res) =>
pattern: "/quran/ayah/page/{pageId}",
contoh: "/quran/ayah/page/604",
},
ayatRange: {
pattern: "/quran/ayah/{surahId}/{start}-{end}",
contoh: "/quran/ayah/114/1-3",
},
},
asbabNujul: {
semua: {
@@ -130,6 +134,7 @@ router.get("/quran/juz/:juzId", quran.getJuz);
router.get("/quran/ayah", quran.getAllAyah);
router.get("/quran/ayah/surah/:surahId", quran.getAyahSurah);
router.get("/quran/ayah/:surahId/:ayahId", quran.getAyah);
router.get("/quran/ayah/:surahId/:startId-:endId", quran.getAyahRange);
router.get("/quran/ayah/juz/:juzId", quran.getAyahJuz);
router.get("/quran/ayah/page/:pageId", quran.getAyahPage);
router.get("/quran/asbab", quran.getAllAsbab);

View File

@@ -21,6 +21,9 @@ const getAyahSurah = (surahId) => {
const getAyah = (surahId, ayahId) => {
return quran.getAyah(surahId, ayahId);
};
const getAyahRange = (surahId, startId, endId) => {
return quran.getAyahRange(surahId, startId, endId);
};
const getAyahJuz = (juzId) => {
return quran.getAyahJuz(juzId);
};
@@ -65,6 +68,7 @@ module.exports = {
getJuz,
getAyahSurah,
getAyah,
getAyahRange,
getAyahJuz,
getAllAyah,
getAyahPage,