-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(types): add types and mappers for hadith apis
- Loading branch information
1 parent
8841e56
commit aa927aa
Showing
10 changed files
with
384 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { HadithLangEnum } from '../types/hadith-lang.enum'; | ||
import { HadithBook } from '../types/hadith.enum'; | ||
|
||
export const hadithBookLanguages: Record<HadithBook, HadithLangEnum[]> = { | ||
[HadithBook.AbuDawud]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Russian, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Bukhari]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Russian, | ||
HadithLangEnum.Tamil, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Dehlawi]: [HadithLangEnum.Arabic, HadithLangEnum.English], | ||
[HadithBook.IbnMajah]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.MuwattaMalik]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Muslim]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Russian, | ||
HadithLangEnum.Tamil, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Nasai]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Russian, | ||
HadithLangEnum.Tamil, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Tirmidhi]: [ | ||
HadithLangEnum.Arabic, | ||
HadithLangEnum.Bengali, | ||
HadithLangEnum.English, | ||
HadithLangEnum.Indonesian, | ||
HadithLangEnum.Russian, | ||
HadithLangEnum.Turkish, | ||
HadithLangEnum.Urdu, | ||
], | ||
[HadithBook.Nawawi40]: [HadithLangEnum.Arabic, HadithLangEnum.Bengali, HadithLangEnum.English], | ||
[HadithBook.Qudsi]: [HadithLangEnum.Arabic, HadithLangEnum.English], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { HadithInfo } from '../types'; | ||
import { HadithApiResponse, HadithEditionApiResponse, HadithInfoApiResponse } from '../types/hadith-api-response'; | ||
import { HadithBySection } from '../types/hadith-by-section'; | ||
import { HadithEdition } from '../types/hadith-edition'; | ||
import { HadithObject } from '../types/hadith-object'; | ||
|
||
export function mapHadithInfoResponse(response: HadithInfoApiResponse): HadithInfo { | ||
const hadithInfo: HadithInfo = {}; | ||
|
||
Object.keys(response).forEach((key) => { | ||
const apiHadith = response[key]; | ||
|
||
hadithInfo[key] = { | ||
hadiths: apiHadith.hadiths.map((hadith) => ({ | ||
arabicNumber: hadith.arabicnumber, | ||
grades: hadith.grades, | ||
hadithNumber: hadith.hadithnumber, | ||
reference: hadith.reference, | ||
})) as any, | ||
metadata: { | ||
lastHadithNumber: apiHadith.metadata.last_hadithnumber, | ||
name: apiHadith.metadata.name, | ||
sections: Object.keys(apiHadith.metadata.section_details).map((sectionKey) => { | ||
const sectionData = apiHadith.metadata.section_details[parseInt(sectionKey)]; | ||
|
||
return { | ||
name: apiHadith.metadata.sections[parseInt(sectionKey)], | ||
details: { | ||
arabicNumberFirst: sectionData.arabicnumber_first, | ||
arabicNumberLast: sectionData.arabicnumber_last, | ||
hadithNumberFirst: sectionData.hadithnumber_first, | ||
hadithNumberLast: sectionData.hadithnumber_last, | ||
}, | ||
}; | ||
}) as any, | ||
}, | ||
}; | ||
}); | ||
|
||
return hadithInfo; | ||
} | ||
|
||
export function mapHadithEditionResponse(apiHadith: HadithEditionApiResponse): HadithEdition { | ||
const edition: HadithEdition = { | ||
hadiths: apiHadith.hadiths.map((hadith) => ({ | ||
grades: hadith.grades, | ||
hadithNumber: hadith.hadithnumber, | ||
reference: hadith.reference, | ||
text: hadith.text, | ||
})) as any, | ||
metadata: { | ||
name: apiHadith.metadata.name, | ||
sections: Object.keys(apiHadith.metadata.section_details).map((sectionKey) => { | ||
const sectionData = apiHadith.metadata.section_details[parseInt(sectionKey)]; | ||
|
||
return { | ||
name: apiHadith.metadata.sections[parseInt(sectionKey)], | ||
details: { | ||
arabicNumberFirst: sectionData.arabicnumber_first, | ||
arabicNumberLast: sectionData.arabicnumber_last, | ||
hadithNumberFirst: sectionData.hadithnumber_first, | ||
hadithNumberLast: sectionData.hadithnumber_last, | ||
}, | ||
}; | ||
}) as any, | ||
}, | ||
}; | ||
|
||
return edition; | ||
} | ||
|
||
export function mapHadithSectionResponse(resp: HadithApiResponse, sectionNo: number): HadithBySection { | ||
return { | ||
metadata: { | ||
name: resp.metadata.name, | ||
section: resp.metadata.section[sectionNo], | ||
sectionDetails: { | ||
arabicNumberFirst: resp.metadata.section_detail[sectionNo].arabicnumber_first, | ||
arabicNumberLast: resp.metadata.section_detail[sectionNo].arabicnumber_last, | ||
hadithNumberFirst: resp.metadata.section_detail[sectionNo].hadithnumber_first, | ||
hadithNumberLast: resp.metadata.section_detail[sectionNo].hadithnumber_last, | ||
}, | ||
}, | ||
hadiths: resp.hadiths.map((hadith) => ({ | ||
arabicNumber: hadith.arabicnumber, | ||
grades: hadith.grades, | ||
hadithNumber: hadith.hadithnumber, | ||
reference: hadith.reference, | ||
text: hadith.text, | ||
})), | ||
}; | ||
} | ||
|
||
export function mapHadithResponse(resp: HadithApiResponse): HadithObject { | ||
return { | ||
metadata: { | ||
name: resp.metadata.name, | ||
section: resp.metadata.section[1], | ||
sectionDetails: { | ||
arabicNumberFirst: resp.metadata.section_detail[1].arabicnumber_first, | ||
arabicNumberLast: resp.metadata.section_detail[1].arabicnumber_last, | ||
hadithNumberFirst: resp.metadata.section_detail[1].hadithnumber_first, | ||
hadithNumberLast: resp.metadata.section_detail[1].hadithnumber_last, | ||
}, | ||
}, | ||
hadith: { | ||
hadithNumber: resp.hadiths[0].hadithnumber, | ||
arabicNumber: resp.hadiths[0].arabicnumber, | ||
text: resp.hadiths[0].text, | ||
grades: resp.hadiths[0].grades, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.