diff --git a/api/database.json b/api/database.json index e2ad6ae..8820ed7 100644 --- a/api/database.json +++ b/api/database.json @@ -13,6 +13,34 @@ "budget": "5000", "neededBy": "2021-12-05", "id": 2 + }, + { + "description": "test request", + "address": "an address", + "budget": "800", + "neededBy": "2021-11-26", + "id": 3 + }, + { + "description": "testing123", + "address": "488", + "budget": "558", + "neededBy": "2021-12-25", + "id": 4 + }, + { + "description": "testing123", + "address": "488", + "budget": "558", + "neededBy": "2021-12-25", + "id": 5 + }, + { + "description": "another test", + "address": "500", + "budget": "30", + "neededBy": "2021-11-30", + "id": 6 } ], "employeeTable": [ diff --git a/scripts/dataAccess.js b/scripts/dataAccess.js index a393b13..d0a56b1 100644 --- a/scripts/dataAccess.js +++ b/scripts/dataAccess.js @@ -5,6 +5,7 @@ const applicationState = { employeeTable:[], jobTable: [] } +const mainContainer = document.querySelector("#container") export const fetchRequests = () => { return fetch(`${API}/serviceRequests`) @@ -49,24 +50,21 @@ export const sendRequest = (userServiceRequest) => { return fetch(`${API}/serviceRequests`, fetchOptions) - .then(response => response.json()) - .then(() => { - - }) + .then(response => response.json()) + .then(() => { + mainContainer.dispatchEvent(new CustomEvent("stateChanged")) + }) +} +export const deleteRequest = (id) => { + return fetch(`${API}/requests/${id}`, { method: "DELETE" }) + .then( + () => { + mainContainer.dispatchEvent(new CustomEvent("stateChanged")) + } + ) } -return fetch(`${API}/requests`, fetchOptions) -.then(response => response.json()) -.then(() => { - mainContainer.dispatchEvent(new CustomEvent("stateChanged")) -}) -mainContainer.addEventListener( - "stateChanged", - customEvent => { - render() - } -) diff --git a/scripts/main.js b/scripts/main.js index d4310c4..f5557bd 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -11,5 +11,11 @@ const render = () => { } ) } +mainContainer.addEventListener( + "stateChanged", + customEvent => { + render() + } +) render()