<commit_before>/*
 * This file is part of the Kreta package.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import {routeActions} from 'react-router-redux';

import {routes} from './../Routes';

import ActionTypes from './../constants/ActionTypes';
import CreateProjectMutationRequest from './../api/graphql/mutation/CreateProjectMutationRequest';
import OrganizationQueryRequest from './../api/graphql/query/OrganizationQueryRequest';
import TaskManagerGraphQl from './../api/graphql/TaskManagerGraphQl';
import Users from './../api/rest/User/Users';

const Actions = {
  fetchOrganization: (slug) => (dispatch) => {
    dispatch({
      type: ActionTypes.CURRENT_ORGANIZATION_FETCHING
    });
    const query = OrganizationQueryRequest.build(slug);

    TaskManagerGraphQl.query(query, dispatch);
    query
      .then(data => {
        const
          organization = data.response.organization,
          ids = [];

        organization.owners.map((owner) => {
          ids.push(owner.id);
        });
        organization.organization_members.map((organizationMember) => {
          ids.push(organizationMember.id);
        });

        Users.get({ids})
          .then((users) => {
            // eslint-disable-next-line
            users.map((user, index) => {
              const
                owner = organization.owners[index],
                reverseIndex = users.length - index - 1,
                member = organization.organization_members[reverseIndex];

              if (typeof owner !== 'undefined' && owner.id === user.id) {
                Object.assign(organization.owners[index], user);
              }

              if (typeof member !== 'undefined' && member.id === user.id) {
                Object.assign(organization.organization_members[reverseIndex], user);
              }
            });

            dispatch({
              type: ActionTypes.CURRENT_ORGANIZATION_RECEIVED,
              organization,
            });
          });
      });
  },
  createProject: (projectInputData) => (dispatch) => {
    dispatch({
      type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATING
    });
    const mutation = CreateProjectMutationRequest.build(projectInputData);

    TaskManagerGraphQl.mutation(mutation, dispatch);
    mutation
      .then(data => {
        const project = data.response.createProject.project;

        dispatch({
          type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATING,
          project,
        });
        dispatch(
          routeActions.push(routes.project.show(project.organization.slug, project.slug))
        );
      })
      .catch((response) => {
        response.then((errors) => {
          dispatch({
            type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATE_ERROR,
            errors
          });
        });
      });
  }
};

export default Actions;<commit_msg>Fixed typo on CurrentOrganization action<commit_after>/*
 * This file is part of the Kreta package.
 *
 * (c) <NAME> <<EMAIL>>
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

import {routeActions} from 'react-router-redux';

import {routes} from './../Routes';

import ActionTypes from './../constants/ActionTypes';
import CreateProjectMutationRequest from './../api/graphql/mutation/CreateProjectMutationRequest';
import OrganizationQueryRequest from './../api/graphql/query/OrganizationQueryRequest';
import TaskManagerGraphQl from './../api/graphql/TaskManagerGraphQl';
import Users from './../api/rest/User/Users';

const Actions = {
  fetchOrganization: (slug) => (dispatch) => {
    dispatch({
      type: ActionTypes.CURRENT_ORGANIZATION_FETCHING
    });
    const query = OrganizationQueryRequest.build(slug);

    TaskManagerGraphQl.query(query, dispatch);
    query
      .then(data => {
        const
          organization = data.response.organization,
          ids = [];

        organization.owners.map((owner) => {
          ids.push(owner.id);
        });
        organization.organization_members.map((organizationMember) => {
          ids.push(organizationMember.id);
        });

        Users.get({ids})
          .then((users) => {
            // eslint-disable-next-line
            users.map((user, index) => {
              const
                owner = organization.owners[index],
                reverseIndex = users.length - index - 1,
                member = organization.organization_members[reverseIndex];

              if (typeof owner !== 'undefined' && owner.id === user.id) {
                Object.assign(organization.owners[index], user);
              }

              if (typeof member !== 'undefined' && member.id === user.id) {
                Object.assign(organization.organization_members[reverseIndex], user);
              }
            });

            dispatch({
              type: ActionTypes.CURRENT_ORGANIZATION_RECEIVED,
              organization,
            });
          });
      });
  },
  createProject: (projectInputData) => (dispatch) => {
    dispatch({
      type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATING
    });
    const mutation = CreateProjectMutationRequest.build(projectInputData);

    TaskManagerGraphQl.mutation(mutation, dispatch);
    mutation
      .then(data => {
        const project = data.response.createProject.project;

        dispatch({
          type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATED,
          project,
        });
        dispatch(
          routeActions.push(routes.project.show(project.organization.slug, project.slug))
        );
      })
      .catch((response) => {
        response.then((errors) => {
          dispatch({
            type: ActionTypes.CURRENT_ORGANIZATION_PROJECT_CREATE_ERROR,
            errors
          });
        });
      });
  }
};

export default Actions;
{'fraction_non_alphanumeric': 0.1258741258741259, 'fraction_numerical': 0.000333000333000333, 'mean_word_length': 2.273569482288828, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4731014', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1582, 'n_words': 305}