From 5d98b8ef8ea8e21405edfe15c05d90b6e1ffc515 Mon Sep 17 00:00:00 2001 From: Amy Date: Tue, 22 Feb 2022 22:07:56 -0500 Subject: [PATCH] Handle books without title, authors, isbn --- lib/books.ts | 9 +++++---- pages/index.tsx | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/books.ts b/lib/books.ts index 92db791..0ba0964 100644 --- a/lib/books.ts +++ b/lib/books.ts @@ -7,7 +7,7 @@ export async function getAllBooks() { const books = new Promise((resolve, reject) => { database.all( - "SELECT title, authors, isbn FROM books", + "SELECT id, title, authors, isbn FROM books WHERE deleted = 0", (error: Error | null, rows: SimpleBook[]) => { if (error) { reject(error); @@ -23,7 +23,8 @@ export async function getAllBooks() { } export interface SimpleBook { - authors: string; - isbn: string; - title: string; + id: number; + title: string | null; + authors: string | null; + isbn: string | null; } diff --git a/pages/index.tsx b/pages/index.tsx index e283020..d64c66e 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -4,15 +4,15 @@ import { getAllBooks, SimpleBook } from "../lib/books"; export default function Home(props: Props) { return ( -
    +
      {props.books.map((book, idx) => { return ( -
    • - {book.title}; {book.authors}; {book.isbn} +
    • + {book.id}; {book.title}; {book.authors}; {book.isbn}
    • ); })} -
+ ); }