gonito-frontend/src/api/getMyEntries.js

56 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-10-14 11:35:48 +02:00
import {API} from '../utils/globals';
import KeyCloakService from '../services/KeyCloakService';
const getMyEntries = (challengeName, setDataOriginalState, setDataStateForSearch, setDataState, setLoadingState, setScoreSorted) => {
2022-10-14 11:35:48 +02:00
fetch(`${API}/challenge-my-submissions/${challengeName}`, {
headers: {'Authorization': `Bearer ${KeyCloakService.getToken()}`}
})
.then(response => response.json())
.then(data => {
2022-11-09 17:49:57 +01:00
setDataOriginalState(data);
let item = {};
let result = [];
2022-11-15 17:29:09 +01:00
let initSetScoreSorted = [];
2022-11-09 17:49:57 +01:00
let tests = data.tests;
for (let submission of data.submissions) {
for (let evaluation of submission.evaluations) {
item = {
...item,
evaluations: {
...item.evaluations,
[`${evaluation.test.metric}.${evaluation.test.name}`]: evaluation.score
}
};
}
for (let test of tests) {
if (!Object.hasOwn(item.evaluations, `${test.metric}.${test.name}`)) {
item = {
...item,
evaluations: {
...item.evaluations,
[`${test.metric}.${test.name}`]: '-1'
}
};
}
}
item = {
...item,
id: submission.id,
submitter: submission.submitter,
when: submission.when,
};
result.push(item);
item = {};
}
2022-11-15 17:29:09 +01:00
// eslint-disable-next-line no-unused-vars
for (let _ of tests) {
initSetScoreSorted.push(false);
}
setScoreSorted(initSetScoreSorted);
setDataStateForSearch(result);
2022-11-09 17:49:57 +01:00
setDataState(result);
setLoadingState(false);
2022-10-14 11:35:48 +02:00
});
};
export default getMyEntries;