Skip to content

Commit

Permalink
Merge pull request #6 from quran/enable-hizb-verses
Browse files Browse the repository at this point in the history
feat: enable verses by hizb API
  • Loading branch information
ahmedriad1 authored Oct 31, 2022
2 parents b2d2eda + 420b4fe commit b6602ab
Show file tree
Hide file tree
Showing 4 changed files with 4,953 additions and 4,911 deletions.
22 changes: 22 additions & 0 deletions docs/pages/verses.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,25 @@ Get a random ayah.
```js
quran.v4.verses.findRandom()
```

## findByHizb

Get all ayahs of a specific Hizb.

- [Quran.com API Docs](https://quran.api-docs.io/v4/verses/by-hizb-number)

**Params:**

`verses.findByHizb(id: HizbNumber, options?: GetVerseOptions)`

| Param | Type | Description |
| ------- | ---------------------------- | ----------------- |
| page | <code>HizbNumber</code> | Quran Hizb number |
| options | <code>GetVerseOptions</code> | |

**Example:**

```js
quran.v4.verses.findByHizb('1')
quran.v4.verses.findByHizb('60')
```
19 changes: 9 additions & 10 deletions src/sdk/v4/verses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ChapterId,
// HizbNumber,
HizbNumber,
JuzNumber,
Language,
PageNumber,
Expand Down Expand Up @@ -146,7 +146,6 @@ const findByJuz = async (juz: JuzNumber, options?: GetVerseOptions) => {
return verses;
};

// TODO: uncomment when API is fixed
/**
* Get all ayahs for a Hizb.
* @description https://quran.api-docs.io/v4/verses/by-hizb-number
Expand All @@ -156,15 +155,15 @@ const findByJuz = async (juz: JuzNumber, options?: GetVerseOptions) => {
* quran.v4.verses.findByHizb('1')
* quran.v4.verses.findByHizb('29')
*/
// const findByHizb = async (hizb: HizbNumber, options?: GetVerseOptions) => {
// if (!Utils.isValidHizb(hizb)) throw new Error('Invalid hizb');
const findByHizb = async (hizb: HizbNumber, options?: GetVerseOptions) => {
if (!Utils.isValidHizb(hizb)) throw new Error('Invalid hizb');

// const params = getVerseOptions(options);
// const url = `/verses/by_hizb/${hizb}`;
// const { verses } = await fetcher<{ verses: Verse[] }>(url, params);
const params = getVerseOptions(options);
const url = `/verses/by_hizb/${hizb}`;
const { verses } = await fetcher<{ verses: Verse[] }>(url, params);

// return verses;
// };
return verses;
};

// TODO: uncomment when API is fixed
/**
Expand Down Expand Up @@ -205,7 +204,7 @@ const verses = {
findByChapter,
findByPage,
findByJuz,
// findByHizb,
findByHizb,
// findByRub,
findRandom,
};
Expand Down
9 changes: 8 additions & 1 deletion test/verses.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ createApiTest('verses', {
rejectParams: ['0' as any],
},
findRandom: {},
findByHizb: {
expect: {
array: true,
},
params: ['1'],
rejectParams: ['0' as any],
},
});

// TODO: test findByHizb and findByRub when fixed
// TODO: test findByRub when fixed
Loading

1 comment on commit b6602ab

@vercel
Copy link

@vercel vercel bot commented on b6602ab Oct 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

api – ./docs

api-quranjs.vercel.app
quranjs.vercel.app
api-git-master-quranjs.vercel.app

Please sign in to comment.