Skip to content

Bugfix/list all books#5

Open
Annie-dev01 wants to merge 3 commits into
mainfrom
bugfix/list-all-books
Open

Bugfix/list all books#5
Annie-dev01 wants to merge 3 commits into
mainfrom
bugfix/list-all-books

Conversation

@Annie-dev01
Copy link
Copy Markdown
Owner

@Annie-dev01 Annie-dev01 commented Oct 13, 2022

  1. The data folder and endpoints(controllers folder) were modified

Comment thread controllers/books.js
let books = []
import fs from 'fs';

export const getBooks = (req, res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

your tabs are still not 4 spaces

Comment thread controllers/books.js

export const getBooks = (req, res) => {
res.send(books);
const books = JSON.parse(fs.readFileSync('./data/books.json'));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use module imports to pull in the json.
import books from './data/books.json

Comment thread controllers/books.js
books.push({ ...book, id: uuidv4()});
res.send(`Book with the name ${book.bookTitle} added to the database!`);
}
let books = [...JSON.parse(fs.readFileSync('./data/books.json'))]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see that this JSON.parse(fs.readFileSync('./data/books.json')) is being used many places. You will probably not need this after implementing the module import suggestion. However, such reused code pieces can be declared at the top of the file and used in all the functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants