Skip to content

Commit

Permalink
database query progress
Browse files Browse the repository at this point in the history
  • Loading branch information
emilysunaryo committed Oct 9, 2023
1 parent 5faceef commit 00a7271
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/database/Queries.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const collectionsRoute = 'https://girlswritenow.org/wp-json/wp/v2/collection';
const storyRoute = 'https://girlswritenow.org/wp-json/wp/v2/story';
const topicRoute = 'https://girlswritenow.org/wp-json/wp/v2/topic';

export const getAllCollections = async (): Promise<JSON[]> => {
// what is the tyoe that goes in this promise?
try {
const response = await fetch(collectionsRoute);
const responseJson = await response.json();
console.log(responseJson);
return responseJson;
} catch (error) {
console.log('Error');
throw error;
}
};

export const getCollectionById = async (id: string): Promise<JSON> => {
try {
const response = await fetch(collectionsRoute);
const responseJson = await response.json();
const responseObj = responseJson.map(
(obj: { id: string }) => obj.id === id,
);
console.log(response);
return responseObj;
} catch (error) {
console.log('Error');
throw error;
}
};

// export const getCollection = async (id: string) => {
// try {
// const response = await fetch("https://girlswritenow.org/wp-json/wp/v2/collection")
// } catch (error){

// }
1 change: 1 addition & 0 deletions src/database/QueriesTestScreen.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// export default function QueriesTestScreen.tsx

0 comments on commit 00a7271

Please sign in to comment.