Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getAllBookHandler = (request, h) => {
- const { name, reading, finished } = request.query;
- let response;
- let ket;
- if (reading !== undefined || finished !== undefined || name !== undefined) {
- if (reading === '1' || finished === '1') {
- ket = true;
- } else {
- ket = false;
- }
- if (reading) {
- response = h.response({
- status: 'success',
- data: {
- books: books.filter((x) => x.reading === ket).map((book) => ({
- id: book.id,
- name: book.name,
- publisher: book.publisher,
- })),
- },
- });
- }
- if (finished) {
- response = h.response({
- status: 'success',
- data: {
- books: books.filter((x) => x.finished === ket).map((book) => ({
- id: book.id,
- name: book.name,
- publisher: book.publisher,
- })),
- },
- });
- }
- if (name) {
- response = h.response({
- status: 'success',
- data: {
- books: books.filter((x) => x.name.toLowerCase().includes(name.toLowerCase()))
- .map((book) => ({
- id: book.id,
- name: book.name,
- publisher: book.publisher,
- })),
- },
- });
- }
- } else {
- response = h.response({
- status: 'success',
- data: {
- books: books.map((book) => ({
- id: book.id,
- name: book.name,
- publisher: book.publisher,
- })),
- },
- });
- }
- return response;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement