42 lines
1.1 KiB
TypeScript
42 lines
1.1 KiB
TypeScript
import { book, author } from "../types/types";
|
|
|
|
const BibblanService = {
|
|
getBooks: async (
|
|
authorid: string | undefined = undefined,
|
|
query: string | undefined = undefined
|
|
): Promise<book[]> => {
|
|
let url = "/api/bibblan/books";
|
|
if (authorid != undefined) {
|
|
url += `/author/${authorid}`;
|
|
} else if (query != undefined && query.length > 0) {
|
|
url += `?query=${encodeURIComponent(query)}`;
|
|
}
|
|
const response = await fetch(url);
|
|
return response.json();
|
|
},
|
|
|
|
getAuthors: async (
|
|
query: string | undefined = undefined
|
|
): Promise<author[]> => {
|
|
let url = "/api/bibblan/authors";
|
|
if (query != undefined && query.length > 0) {
|
|
url += `?query=${encodeURIComponent(query)}`;
|
|
}
|
|
const response = await fetch(url);
|
|
return response.json();
|
|
},
|
|
|
|
getSeries: async (
|
|
query: string | undefined = undefined
|
|
): Promise<author[]> => {
|
|
let url = "/api/bibblan/series";
|
|
if (query != undefined && query.length > 0) {
|
|
url += `?query=${encodeURIComponent(query)}`;
|
|
}
|
|
const response = await fetch(url);
|
|
return response.json();
|
|
},
|
|
};
|
|
|
|
export default BibblanService;
|