Skip to content

Commit

Permalink
chore: minor changes in api.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Mar 6, 2024
1 parent d676ba1 commit 093c3ad
Showing 1 changed file with 16 additions and 48 deletions.
64 changes: 16 additions & 48 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,94 +2,70 @@ import { API_URL } from '../config';
import { fetchData } from '@utils/fetchData';

async function getAllBooks() {
const data = await fetchData(API_URL);

return data;
return await fetchData(API_URL);
}

async function getAllSearchBooks(book: string) {
const data = await fetchData(`${API_URL}/books/search?q=${book}`);

return data;
return await fetchData(`${API_URL}/books/search?q=${book}`);
}

async function getBooksPaginate(page: number | undefined) {
const data = await fetchData(`${API_URL}/books?limit=10&page=${page}`);

return data;
return await fetchData(`${API_URL}/books?limit=10&page=${page}`);
}

async function getBook(pathUrl: string | undefined) {
const data = await fetchData(`${API_URL}/book/path/${pathUrl}`);

return data;
return await fetchData(`${API_URL}/book/path/${pathUrl}`);
}

async function postBook(books: any) {
const post = await fetchData(`${API_URL}/book/post`, {
return await fetchData(`${API_URL}/book/post`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(books),
});

return post;
}

async function getBooksFilter(
query: string | undefined,
param: string | undefined,
) {
const data = await fetchData(`${API_URL}/books?${query}=${param}`);

return data;
return await fetchData(`${API_URL}/books?${query}=${param}`);
}

async function getMoreBooks() {
const data = await fetchData(`${API_URL}/books/more-books`);

return data;
return await fetchData(`${API_URL}/books/more-books`);
}

async function getRelatedBooks(id: string | undefined) {
const data = await fetchData(`${API_URL}/books/related-books/${id}`);

return data;
return await fetchData(`${API_URL}/books/related-books/${id}`);
}

async function getMoreBooksAuthors(id: string | undefined) {
const data = await fetchData(`${API_URL}/books/more-books-authors/${id}`);

return data;
return await fetchData(`${API_URL}/books/more-books-authors/${id}`);
}

async function getAllFilterOptions() {
const data = await fetchData(`${API_URL}/books/options`);

return data;
return await fetchData(`${API_URL}/books/options`);
}

async function updateBook(id: string | undefined, books: any) {
const data = await fetchData(`${API_URL}/book/update/${id}`, {
return await fetchData(`${API_URL}/book/update/${id}`, {
method: 'PATCH',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(books),
});

return data;
}

async function deleteBook(id: string | undefined) {
const data = await fetchData(`${API_URL}/book/delete/${id}`, {
return await fetchData(`${API_URL}/book/delete/${id}`, {
method: 'DELETE',
});

return data;
}

// Usuarios

async function postRegister(token: string, body: any) {
const data = await fetchData(`${API_URL}/auth/register`, {
return await fetchData(`${API_URL}/auth/register`, {
method: 'POST',
// credentials: 'include',
headers: {
Expand All @@ -98,14 +74,10 @@ async function postRegister(token: string, body: any) {
},
body: JSON.stringify({ username: body }),
});

return data;
}

async function getCheckUser(id: string | undefined) {
const data = await fetchData(`${API_URL}/users/check-user/${id}`);

return data;
return await fetchData(`${API_URL}/users/check-user/${id}`);
}

async function getUserAndBooks(
Expand All @@ -114,7 +86,7 @@ async function getUserAndBooks(
token: string | null,
page: number | undefined,
) {
const data = await fetchData(
return await fetchData(
`${API_URL}/users/${username}/my-books/${userId}?limit=5&page=${page}`,
{
method: 'GET',
Expand All @@ -123,16 +95,12 @@ async function getUserAndBooks(
},
},
);

return data;
}

async function deleteAccount(id: string | undefined) {
const data = await fetchData(`${API_URL}/users/delete-account/${id}`, {
return await fetchData(`${API_URL}/users/delete-account/${id}`, {
method: 'DELETE',
});

return data;
}

export {
Expand Down

0 comments on commit 093c3ad

Please sign in to comment.