{"size": 1348, "ext": "js", "max_stars_repo_path": "src/sagas/invitation.js", "max_stars_repo_name": "pekkis/mhm-97-remake", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/sagas/invitation.js", "max_issues_repo_name": "pekkis/mhm-97-remake", "max_issues_repo_issues_event_min_datetime": "2021-05-11T04:52:00.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T00:28:50.000Z", "max_forks_repo_path": "src/sagas/invitation.js", "max_forks_repo_name": "mhm-online/mhm-97-remake", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 29.3043478261, "max_line_length": 111, "alphanum_fraction": 0.6698813056}
import { putResolve } from "redux-saga/effects";
import tournamentList from "../data/tournaments";
import { call, select, put } from "redux-saga/effects";

import { INVITATION_ADD, INVITATION_ACCEPT } from "../ducks/invitation";
import { addNotification } from "./notification";
import { managersTeamId } from "../data/selectors";
import { addTeamToCompetition } from "./game";

export function* acceptInvitation(managerId, id) {
  const team = yield select(managersTeamId(managerId));

  yield putResolve({
    type: INVITATION_ACCEPT,
    payload: { manager: managerId, id }
  });

  yield call(addTeamToCompetition, "tournaments", team);

  yield call(
    addNotification,
    managerId,
    "Hyväksyit turnauskutsun. Sihteerisi vastasi kaikkiin muihin potentiaalisiin turnauskutsuihin kieltävästi."
  );
}

export function* createInvitations() {
  const managers = yield select(state => state.manager.get("managers"));

  for (const [managerId] of managers) {
    for (const [tournamentId, tournament] of tournamentList.entries()) {
      const isInvited = yield call(tournament.get("isInvited"), managerId);
      if (isInvited) {
        yield put({
          type: INVITATION_ADD,
          payload: {
            manager: managerId,
            tournament: tournamentId,
            duration: 3
          }
        });
      }
    }
  }
}
