-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathsubmissionsAPI.js
More file actions
40 lines (37 loc) · 1.15 KB
/
submissionsAPI.js
File metadata and controls
40 lines (37 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import axiosInstance from "../axiosInstance.js";
import moment from "moment";
export default {
async getSubmissions() {
const response = await axiosInstance.get(`/api/info/submissions`);
let submissions = [];
response.data.forEach(element => {
// solvedTime is solved time is given format
element.solvedTime = moment(element.solvedAt).format(
"HH:mm:ss; MMMM Do, YYYY"
);
submissions.push(element);
});
return submissions;
},
// Group submissions by username for efficient processing
groupSubmissionsByUsers(submissions, usernames) {
const userSubmissions = {};
usernames.forEach(username => {
userSubmissions[username] = submissions.filter(sub => sub.username === username);
});
return userSubmissions;
},
async fetchAsCSV() {
return await axiosInstance({
method: "get",
responseType: "blob",
url: `/api/info/submissions?format=csv`
});
},
async getUserSubs(username) {
const submissions = await this.getSubmissions();
const submission = submissions.filter(sub => sub.username === username);
console.log(submission);
return submission;
}
};