{"size": 778, "ext": "js", "max_stars_repo_path": "src/services/assignments/assignmentServices.js", "max_stars_repo_name": "push-pin/push-pin", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/assignments/assignmentServices.js", "max_issues_repo_name": "push-pin/push-pin", "max_issues_repo_issues_event_min_datetime": "2020-07-17T02:38:33.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-17T23:12:07.000Z", "max_forks_repo_path": "src/services/assignments/assignmentServices.js", "max_forks_repo_name": "push-pin/push-pin", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 7, "max_forks_count": null, "avg_line_length": 23.5757575758, "max_line_length": 93, "alphanum_fraction": 0.5809768638}
import { get } from '../request';

export const fetchAssesByCourse = (courseId, studentId) => {
  return get(`/api/v1/assignments/courseassignments/course/${courseId}/student/${studentId}`)
    .then(res => leanedAsses(res));
};

const leanedAsses = ({ asses, subs }) => {
  const mapped = asses.map(ass => {
    let grade = false;
    let submitted = false;

    subs.forEach(sub => {
      if(sub.assignment._id === ass._id) {
        grade = sub.graded;
        submitted = true;
      }});

    return {
      _id: ass._id,
      type: ass.type,
      title: ass.title,
      classDate: ass.classDate,
      dateDue: ass.dateDue,
      submitted: submitted,
      grade: grade
    };
  });

  mapped.sort((a, b) => (a.classDate > b.classDate) ? 1 : -1);
  return mapped;
};
