2021-01-21 16:09:23 +01:00
|
|
|
import { xhrGet } from '../../xhr';
|
|
|
|
|
export const jobs = {
|
|
|
|
|
state: {
|
|
|
|
|
jobs: [],
|
|
|
|
|
insights: {},
|
2021-05-13 20:27:42 +02:00
|
|
|
processingTimes: {},
|
2021-01-21 16:09:23 +01:00
|
|
|
},
|
|
|
|
|
reducers: {
|
|
|
|
|
setJobs: (state, payload) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
jobs: Object.freeze(payload),
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-05-13 20:27:42 +02:00
|
|
|
setProcessingTimes: (state, payload) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
processingTimes: Object.freeze(payload),
|
|
|
|
|
};
|
|
|
|
|
},
|
2021-01-21 16:09:23 +01:00
|
|
|
setJobInsights: (state, payload, jobId) => {
|
|
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
insights: {
|
|
|
|
|
...state.insights,
|
|
|
|
|
[jobId]: Object.freeze(payload),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
effects: {
|
|
|
|
|
async getJobs() {
|
|
|
|
|
try {
|
|
|
|
|
const response = await xhrGet('/api/jobs');
|
|
|
|
|
this.setJobs(response.json);
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
console.error(`Error while trying to get resource for api/jobs. Error:`, Exception);
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-05-13 20:27:42 +02:00
|
|
|
async getProcessingTimes() {
|
|
|
|
|
try {
|
|
|
|
|
const response = await xhrGet('/api/jobs/processingTimes');
|
|
|
|
|
this.setProcessingTimes(response.json);
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
console.error(`Error while trying to get resource for api/processingTimes. Error:`, Exception);
|
|
|
|
|
}
|
|
|
|
|
},
|
2021-01-21 16:09:23 +01:00
|
|
|
async getInsightDataForJob(jobId) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await xhrGet(`/api/jobs/insights/${jobId}`);
|
|
|
|
|
this.setJobInsights(response.json, jobId);
|
|
|
|
|
} catch (Exception) {
|
|
|
|
|
console.error(`Error while trying to get resource for api/jobs/insights. Error:`, Exception);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|