This repository has been archived on 2026-10-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
a_sink_repair/scripts/dataAccess.js
T
2021-11-04 15:14:09 -05:00

53 lines
1.5 KiB
JavaScript

const API = "http://localhost:8088"
const applicationState = {
serviceRequests: [],
employeeTable:[],
jobTable: []
}
export const fetchRequests = () => {
return fetch(`${API}/serviceRequests`)
.then(response => response.json())
.then(
(serviceRequests) => {
// Store the external state of in application state
applicationState.serviceRequests = serviceRequests
}
)
}
export const fetchJobTable = () => {
return fetch(`${API}/jobTable`)
.then(response => response.json())
.then(
(jobTable) => {
// Stores the external state of jobTable in application state
applicationState.jobTable = jobTable
}
)
}
export const fetchEmpTable = () => {
return fetch(`${API}/employeeTable`)
.then(response => response.json())
.then(
(employeeTable) => {
// Stores the external state of jobTable in application state
applicationState.employeeTable = employeeTable
}
)
}
export const getRequests = () => {
return applicationState.serviceRequests.map(serviceRequest => ({...serviceRequest}))
}
export const getEmployees = () => {
return applicationState.employeeTable.map(employee => ({...employee}))
}
export const getJobTable = () => {
return applicationState.jobTable.map(job => ({...job}))
}
// Need copies of permanent state set as empty arrays, matching the keys in your JSON file