Skip to content

Commit

Permalink
Merge pull request #2 from Deri-Kurniawan/development
Browse files Browse the repository at this point in the history
Development Completed
  • Loading branch information
Deri-Kurniawan authored Oct 1, 2021
2 parents b59ce11 + 54726fa commit 8085319
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ const init = async () => {
reading,
insertedAt,
updatedAt
}

console.log(newBook);
};

if (name === null || name.length <= 0) {
return h.response({
Expand Down Expand Up @@ -89,20 +87,50 @@ const init = async () => {
path: '/books',
handler: (request, h) => {

const book = books.map(({
id,
name,
publisher,
}) => ({
id,
name,
publisher,
}));
const {
reading = null,
finished = null,
name = null,
} = request.query;

let allBooks = [];

if (reading === null && finished === null && name === null) {
allBooks = books;
return h.response({
"status": "success",
"data": {
"books": allBooks.map(({
id,
name,
publisher,
}) => ({
id,
name,
publisher,
})),
}
}).code(200).type('application/json').charset('utf-8');
} else if (reading !== null) {
allBooks = books.filter((book) => Number(reading) === Number(book.reading));
} else if (finished !== null) {
allBooks = books.filter((book) => Number(finished) === Number(book.finished));
} else if (name !== null) {
allBooks = books.filter((book) => book.name.toLowerCase().includes(name.toLowerCase()));
}

return h.response({
"status": "success",
"data": {
"books": book,
"books": allBooks.map(({
id,
name,
publisher,
}) => ({
id,
name,
publisher,
})),
}
}).code(200).type('application/json').charset('utf-8');

Expand Down

0 comments on commit 8085319

Please sign in to comment.