Handle books without title, authors, isbn

This commit is contained in:
Amy 2022-02-22 22:07:56 -05:00
parent 337af21679
commit 5d98b8ef8e
2 changed files with 9 additions and 8 deletions

View File

@ -7,7 +7,7 @@ export async function getAllBooks() {
const books = new Promise<SimpleBook[]>((resolve, reject) => { const books = new Promise<SimpleBook[]>((resolve, reject) => {
database.all( database.all(
"SELECT title, authors, isbn FROM books", "SELECT id, title, authors, isbn FROM books WHERE deleted = 0",
(error: Error | null, rows: SimpleBook[]) => { (error: Error | null, rows: SimpleBook[]) => {
if (error) { if (error) {
reject(error); reject(error);
@ -23,7 +23,8 @@ export async function getAllBooks() {
} }
export interface SimpleBook { export interface SimpleBook {
authors: string; id: number;
isbn: string; title: string | null;
title: string; authors: string | null;
isbn: string | null;
} }

View File

@ -4,15 +4,15 @@ import { getAllBooks, SimpleBook } from "../lib/books";
export default function Home(props: Props) { export default function Home(props: Props) {
return ( return (
<ol> <ul>
{props.books.map((book, idx) => { {props.books.map((book, idx) => {
return ( return (
<li key={`${idx}_${book.isbn}`}> <li key={`${idx}_${book.isbn ?? ""}`}>
{book.title}; {book.authors}; {book.isbn} {book.id}; {book.title}; {book.authors}; {book.isbn}
</li> </li>
); );
})} })}
</ol> </ul>
); );
} }