Skip to content

Commit

Permalink
feat: no null values in verses range and not array in one verse read
Browse files Browse the repository at this point in the history
  • Loading branch information
Atticus64 committed Dec 22, 2023
1 parent 4d8f9a9 commit 8d00ec0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/controllers/version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "hono/context.ts";
import { getVersionName, Version } from "$/scraping/scrape.ts";
import { getVersionName, Verse, Version } from "$/scraping/scrape.ts";
import { connect } from "$/database/index.ts";
import { searchProps } from "$/middlewares/search.ts";
import { Book, books } from "$/scraping/index.ts";
Expand Down Expand Up @@ -209,8 +209,25 @@ function toValidName(bookName: string): string {
}

return formatedBook
}

function deleteNullValues(data: Verse[]) {

return data.map(v => {

if (v.study) {
return v
} else {
return {
verse: v.verse,
number: v.number,
id: v.id
}
}
})

}

async function getOneVerse(table: Table, bookName: string, chapter: number, verse_num: number) {

try {
Expand All @@ -223,9 +240,9 @@ async function getOneVerse(table: Table, bookName: string, chapter: number, vers
JOIN books ON books.id = chapters.book_id WHERE chapter = ${chapter}
AND books.name = ${book} AND ${sql(table)}.number = ${verse_num};
`;
const verse = data[0];


return data;
return verse;
} catch (error) {
console.log(error);
return []
Expand Down Expand Up @@ -270,7 +287,8 @@ async function getVerses(table: Table, bookName: string, chapt: number) {
JOIN books ON books.id = chapters.book_id WHERE chapter = ${chapt} AND books.name = ${book};
`;

return data
const verses = deleteNullValues(data)
return verses;

} catch (error) {
console.log(error);
Expand Down
2 changes: 1 addition & 1 deletion src/scraping/scrape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const getVersionName = (v: Version): string => {
}
};

type Verse = {
export type Verse = {
verse: string;
number: number;
study?: string;
Expand Down

0 comments on commit 8d00ec0

Please sign in to comment.