Flask backend with Vue 3 frontend for shop floor machine management. Includes database schema export for MySQL shopdb_flask database. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
393 lines
8.5 KiB
JavaScript
393 lines
8.5 KiB
JavaScript
import axios from 'axios'
|
|
|
|
const api = axios.create({
|
|
baseURL: '/api',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
|
|
// Add auth token to requests
|
|
api.interceptors.request.use(config => {
|
|
const token = localStorage.getItem('token')
|
|
if (token) {
|
|
config.headers.Authorization = `Bearer ${token}`
|
|
}
|
|
return config
|
|
})
|
|
|
|
// Handle 401 errors (token expired) - only redirect if user was logged in
|
|
api.interceptors.response.use(
|
|
response => response,
|
|
error => {
|
|
if (error.response?.status === 401) {
|
|
const hadToken = localStorage.getItem('token')
|
|
localStorage.removeItem('token')
|
|
localStorage.removeItem('user')
|
|
// Only redirect if user was previously logged in (session expired)
|
|
if (hadToken) {
|
|
window.location.href = '/login'
|
|
}
|
|
}
|
|
return Promise.reject(error)
|
|
}
|
|
)
|
|
|
|
export default api
|
|
|
|
// Auth API
|
|
export const authApi = {
|
|
login(username, password) {
|
|
return api.post('/auth/login', { username, password })
|
|
},
|
|
logout() {
|
|
return api.post('/auth/logout')
|
|
},
|
|
me() {
|
|
return api.get('/auth/me')
|
|
},
|
|
refresh() {
|
|
const refreshToken = localStorage.getItem('refreshToken')
|
|
return api.post('/auth/refresh', {}, {
|
|
headers: { Authorization: `Bearer ${refreshToken}` }
|
|
})
|
|
}
|
|
}
|
|
|
|
// Machines API
|
|
export const machinesApi = {
|
|
list(params = {}) {
|
|
return api.get('/machines', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/machines/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/machines', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/machines/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/machines/${id}`)
|
|
},
|
|
updateCommunication(id, data) {
|
|
return api.put(`/machines/${id}/communication`, data)
|
|
},
|
|
// Relationships
|
|
getRelationships(id) {
|
|
return api.get(`/machines/${id}/relationships`)
|
|
},
|
|
createRelationship(id, data) {
|
|
return api.post(`/machines/${id}/relationships`, data)
|
|
},
|
|
deleteRelationship(relationshipId) {
|
|
return api.delete(`/machines/relationships/${relationshipId}`)
|
|
}
|
|
}
|
|
|
|
// Relationship Types API
|
|
export const relationshipTypesApi = {
|
|
list() {
|
|
return api.get('/machines/relationshiptypes')
|
|
},
|
|
create(data) {
|
|
return api.post('/machines/relationshiptypes', data)
|
|
}
|
|
}
|
|
|
|
// Machine Types API
|
|
export const machinetypesApi = {
|
|
list(params = {}) {
|
|
return api.get('/machinetypes', { params })
|
|
},
|
|
create(data) {
|
|
return api.post('/machinetypes', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/machinetypes/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/machinetypes/${id}`)
|
|
}
|
|
}
|
|
|
|
// Statuses API
|
|
export const statusesApi = {
|
|
list(params = {}) {
|
|
return api.get('/statuses', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/statuses/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/statuses', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/statuses/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/statuses/${id}`)
|
|
}
|
|
}
|
|
|
|
// Vendors API
|
|
export const vendorsApi = {
|
|
list(params = {}) {
|
|
return api.get('/vendors', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/vendors/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/vendors', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/vendors/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/vendors/${id}`)
|
|
}
|
|
}
|
|
|
|
// Locations API
|
|
export const locationsApi = {
|
|
list(params = {}) {
|
|
return api.get('/locations', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/locations/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/locations', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/locations/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/locations/${id}`)
|
|
}
|
|
}
|
|
|
|
// Printers API
|
|
export const printersApi = {
|
|
list(params = {}) {
|
|
return api.get('/printers/', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/printers/${id}`)
|
|
},
|
|
updateExtension(id, data) {
|
|
return api.put(`/printers/${id}/printerdata`, data)
|
|
},
|
|
updateCommunication(id, data) {
|
|
return api.put(`/printers/${id}/communication`, data)
|
|
},
|
|
getSupplies(id) {
|
|
return api.get(`/printers/${id}/supplies`)
|
|
},
|
|
getDrivers(id) {
|
|
return api.get(`/printers/${id}/drivers`)
|
|
},
|
|
lowSupplies() {
|
|
return api.get('/printers/lowsupplies')
|
|
},
|
|
dashboardSummary() {
|
|
return api.get('/printers/dashboard/summary')
|
|
},
|
|
drivers: {
|
|
list() {
|
|
return api.get('/printers/drivers')
|
|
},
|
|
create(data) {
|
|
return api.post('/printers/drivers', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/printers/drivers/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/printers/drivers/${id}`)
|
|
}
|
|
},
|
|
supplyTypes: {
|
|
list() {
|
|
return api.get('/printers/supplytypes')
|
|
},
|
|
create(data) {
|
|
return api.post('/printers/supplytypes', data)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Dashboard API
|
|
export const dashboardApi = {
|
|
summary() {
|
|
return api.get('/dashboard/summary')
|
|
}
|
|
}
|
|
|
|
// Models API
|
|
export const modelsApi = {
|
|
list(params = {}) {
|
|
return api.get('/models', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/models/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/models', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/models/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/models/${id}`)
|
|
}
|
|
}
|
|
|
|
// PC Types API
|
|
export const pctypesApi = {
|
|
list(params = {}) {
|
|
return api.get('/pctypes', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/pctypes/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/pctypes', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/pctypes/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/pctypes/${id}`)
|
|
}
|
|
}
|
|
|
|
// Operating Systems API
|
|
export const operatingsystemsApi = {
|
|
list(params = {}) {
|
|
return api.get('/operatingsystems', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/operatingsystems/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/operatingsystems', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/operatingsystems/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/operatingsystems/${id}`)
|
|
}
|
|
}
|
|
|
|
// Business Units API
|
|
export const businessunitsApi = {
|
|
list(params = {}) {
|
|
return api.get('/businessunits', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/businessunits/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/businessunits', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/businessunits/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/businessunits/${id}`)
|
|
}
|
|
}
|
|
|
|
// Applications API
|
|
export const applicationsApi = {
|
|
list(params = {}) {
|
|
return api.get('/applications', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/applications/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/applications', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/applications/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/applications/${id}`)
|
|
},
|
|
// Versions
|
|
getVersions(appId) {
|
|
return api.get(`/applications/${appId}/versions`)
|
|
},
|
|
createVersion(appId, data) {
|
|
return api.post(`/applications/${appId}/versions`, data)
|
|
},
|
|
// Get PCs that have this app installed
|
|
getInstalledOn(appId) {
|
|
return api.get(`/applications/${appId}/installed`)
|
|
},
|
|
// Machine applications (installed apps)
|
|
getMachineApps(machineId) {
|
|
return api.get(`/applications/machines/${machineId}`)
|
|
},
|
|
installApp(machineId, data) {
|
|
return api.post(`/applications/machines/${machineId}`, data)
|
|
},
|
|
uninstallApp(machineId, appId) {
|
|
return api.delete(`/applications/machines/${machineId}/${appId}`)
|
|
},
|
|
updateInstalledApp(machineId, appId, data) {
|
|
return api.put(`/applications/machines/${machineId}/${appId}`, data)
|
|
},
|
|
// Support teams
|
|
getSupportTeams() {
|
|
return api.get('/applications/supportteams')
|
|
},
|
|
createSupportTeam(data) {
|
|
return api.post('/applications/supportteams', data)
|
|
},
|
|
// App owners
|
|
getAppOwners() {
|
|
return api.get('/applications/appowners')
|
|
},
|
|
createAppOwner(data) {
|
|
return api.post('/applications/appowners', data)
|
|
}
|
|
}
|
|
|
|
// Search API
|
|
export const searchApi = {
|
|
search(query) {
|
|
return api.get('/search', { params: { q: query } })
|
|
}
|
|
}
|
|
|
|
// Knowledge Base API
|
|
export const knowledgebaseApi = {
|
|
list(params = {}) {
|
|
return api.get('/knowledgebase', { params })
|
|
},
|
|
get(id) {
|
|
return api.get(`/knowledgebase/${id}`)
|
|
},
|
|
create(data) {
|
|
return api.post('/knowledgebase', data)
|
|
},
|
|
update(id, data) {
|
|
return api.put(`/knowledgebase/${id}`, data)
|
|
},
|
|
delete(id) {
|
|
return api.delete(`/knowledgebase/${id}`)
|
|
},
|
|
trackClick(id) {
|
|
return api.post(`/knowledgebase/${id}/click`)
|
|
},
|
|
getStats() {
|
|
return api.get('/knowledgebase/stats')
|
|
}
|
|
}
|