Zpcolburn / Heavy-Track

1 stars 0 forks source link

MVP - API calls for Equipment #15

Closed Zpcolburn closed 1 month ago

Zpcolburn commented 1 month ago

User Story

No user will be able to see this but it does allow them to use the website features.

Acceptance Criteria

List of the different API calls needed

Dependecies

All Planning must be done. Make sure all of these calls are tested in postman.

5

Dev Notes

This is a sample from simply books import { clientCredentials } from '../utils/client'; // API CALLS FOR BOOKS

const endpoint = clientCredentials.databaseURL;

const getBooks = (uid) => new Promise((resolve, reject) => { fetch(${endpoint}/books.json?orderBy="uid"&equalTo="${uid}", { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then((data) => resolve(Object.values(data))) .catch(reject); });

// TODO: DELETE BOOK const deleteBook = (firebaseKey) => new Promise((resolve, reject) => { fetch(${endpoint}/books/${firebaseKey}.json, { method: 'DELETE', headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then((data) => resolve((data))) .catch(reject); });

// TODO: GET SINGLE BOOK const getSingleBook = (firebaseKey) => new Promise((resolve, reject) => { fetch(${endpoint}/books/${firebaseKey}.json, { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then((data) => resolve(data)) .catch(reject); });

// TODO: CREATE BOOK const createBook = (payload) => new Promise((resolve, reject) => { fetch(${endpoint}/books.json, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => resolve(data)) .catch(reject); });

// TODO: UPDATE BOOK const updateBook = (payload) => new Promise((resolve, reject) => { fetch(${endpoint}/books/${payload.firebaseKey}.json, { method: 'PATCH', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(payload), }) .then((response) => response.json()) .then((data) => resolve(data)) .catch(reject); });

const getBooksByAuthor = (firebaseKey) => new Promise((resolve, reject) => { fetch(${endpoint}/books.json?orderBy="author_id"&equalTo="${firebaseKey}", { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then((data) => resolve(Object.values(data))) .catch(reject); });

const booksOnSale = (uid) => new Promise((resolve, reject) => { fetch(${endpoint}/books.json?orderBy="uid"&equalTo="${uid}", { method: 'GET', headers: { 'Content-Type': 'application/json', }, }) .then((response) => response.json()) .then((data) => { const onSale = Object.values(data).filter((item) => item.sale); resolve(onSale); }) .catch(reject); });

export { getBooks, createBook, booksOnSale, deleteBook, getSingleBook, updateBook, getBooksByAuthor, };