<commit_before>import request from 'superagent';

const dataService = store => next => (action) => {
  // Pass all actions through by default
  next(action);
  const url = 'http://localhost:8002/api';
  switch (action.type) {
    // Signin a user
    case 'SIGN_IN':
      request.post(`${url}/user/signin`)
        .send({
          email: action.email,
          password: <PASSWORD>,
        })
        .end((err, res) => {
          // Return the first error message when there are many
          if (err) {
            // Ignore browser errors which do not have a res object
            if (res) {
              return next({
                type: 'SIGN_IN_ERROR',
                message: res.body.message
              });
            }
          }
          const userDetails = res.body.user;
          userDetails.token = res.body.token;
          next({
            type: 'SIGN_IN_SUCCESS',
            userDetails
          });
        });
      break;
    // Signup a new user
    case 'SIGN_UP':
      request.post(`${url}/user/signup`)
        .send({
          firstName: action.firstName,
          lastName: action.lastName,
          email: action.email,
          phone: action.phone,
          password: <PASSWORD>,
        })
        .end((err, res) => {
          if (err) {
            // Ignore browser errors which do not have a res object
            if (res) {
              if (res.body.messages) {
                // Return the first error message when there are many
                return next({
                  type: 'SIGN_UP_ERROR',
                  message: res.body.messages[0]
                });
              } else {
                return next({
                  type: 'SIGN_UP_ERROR',
                  message: res.body.message
                });
              }
            }
          }
          const userDetails = res.body.user;
          userDetails.token = res.body.token;
          next({
            type: 'SIGN_UP_SUCCESS',
            userDetails
          });
        });
      break;
    // Post a message to a group
    case 'POST_MESSAGE':
      request.post(`${url}/group/${action.groupId}/message`)
        .set('x-access-token', action.token)
        .send({
          body: action.body,
          priority: action.priority,
          isComment: action.isComment,
          senderId: action.senderId,
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'POST_MESSAGE_ERROR',
              message: err.message
            });
          }
          const message = res.body.message;
          next({
            type: 'POST_MESSAGE_SUCCESS',
            message,
            groupId: action.groupId
          });
        });
      break;
    // Add group members
    case 'ADD_MEMBER':
      request.post(`${url}/group/${action.groupId}/user`)
        .set('x-access-token', action.token)
        .send({
          email: action.email,
          adderId: action.adderId,
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'ADD_MEMBER_ERROR',
              message: err.message
            });
          }
          const addedMembers = res.body;
          next({
            type: 'ADD_MEMBER_SUCCESS',
            addedMembers,
            groupId: action.groupId
          });
        });
      break;
    // Delete a group
    case 'DELETE_A_GROUP':
      request
        .delete(`${url}/group/${action.groupId}/delete`)
        .set('x-access-token', action.token)
        .send({
          ownerId: action.ownerId
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'DELETE_A_GROUP_ERROR',
              message: err.message
            });
          }
          const data = res.body;
          next({
            type: 'DELETE_A_GROUP_SUCCESS',
            data
          });
        });
      break;
    // Create a new group
    case 'CREATE_GROUP':
      request.post(`${url}/group`)
        .set('x-access-token', action.token)
        .send({
          creatorId: action.creatorId,
          title: action.title,
          description: action.description,
          initialMembers: action.initialMembers
        })
        .end((err, res) => {
          if (err) {
            // Ignore browser errors which do not have a res object<commit_msg>point to heroku app<commit_after>import request from 'superagent';

const dataService = store => next => (action) => {
  // Pass all actions through by default
  next(action);
  const url = 'http://postit-api-victor.herokuapp.com/api';
  switch (action.type) {
    // Signin a user
    case 'SIGN_IN':
      request.post(`${url}/user/signin`)
        .send({
          email: action.email,
          password: action.password,
        })
        .end((err, res) => {
          // Return the first error message when there are many
          if (err) {
            // Ignore browser errors which do not have a res object
            if (res) {
              return next({
                type: 'SIGN_IN_ERROR',
                message: res.body.message
              });
            }
          }
          const userDetails = res.body.user;
          userDetails.token = res.body.token;
          next({
            type: 'SIGN_IN_SUCCESS',
            userDetails
          });
        });
      break;
    // Signup a new user
    case 'SIGN_UP':
      request.post(`${url}/user/signup`)
        .send({
          firstName: action.firstName,
          lastName: action.lastName,
          email: action.email,
          phone: action.phone,
          password: <PASSWORD>,
        })
        .end((err, res) => {
          if (err) {
            // Ignore browser errors which do not have a res object
            if (res) {
              if (res.body.messages) {
                // Return the first error message when there are many
                return next({
                  type: 'SIGN_UP_ERROR',
                  message: res.body.messages[0]
                });
              } else {
                return next({
                  type: 'SIGN_UP_ERROR',
                  message: res.body.message
                });
              }
            }
          }
          const userDetails = res.body.user;
          userDetails.token = res.body.token;
          next({
            type: 'SIGN_UP_SUCCESS',
            userDetails
          });
        });
      break;
    // Post a message to a group
    case 'POST_MESSAGE':
      request.post(`${url}/group/${action.groupId}/message`)
        .set('x-access-token', action.token)
        .send({
          body: action.body,
          priority: action.priority,
          isComment: action.isComment,
          senderId: action.senderId,
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'POST_MESSAGE_ERROR',
              message: err.message
            });
          }
          const message = res.body.message;
          next({
            type: 'POST_MESSAGE_SUCCESS',
            message,
            groupId: action.groupId
          });
        });
      break;
    // Add group members
    case 'ADD_MEMBER':
      request.post(`${url}/group/${action.groupId}/user`)
        .set('x-access-token', action.token)
        .send({
          email: action.email,
          adderId: action.adderId,
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'ADD_MEMBER_ERROR',
              message: err.message
            });
          }
          const addedMembers = res.body;
          next({
            type: 'ADD_MEMBER_SUCCESS',
            addedMembers,
            groupId: action.groupId
          });
        });
      break;
    // Delete a group
    case 'DELETE_A_GROUP':
      request
        .delete(`${url}/group/${action.groupId}/delete`)
        .set('x-access-token', action.token)
        .send({
          ownerId: action.ownerId
        })
        .end((err, res) => {
          if (err) {
            return next({
              type: 'DELETE_A_GROUP_ERROR',
              message: err.message
            });
          }
          const groupId = action.groupId;
          next({
            type: 'DELETE_A_GROUP_SUCCESS',
            groupId
          });
        });
      break;
    // Create a new group
    case 'CREATE_GROUP':
      request.post(`${url}/group`)
        .set('x-access-token', action.token)
        .send({
          creatorId: action.creatorId,
          title: action.title,
          description: action.description,
          initialMembers: action.initialMembers
        })
        .end((err, res) => {
          if (err) {
            // Ignore browser errors which do not have a res object
{'fraction_non_alphanumeric': 0.11938266000907853, 'fraction_numerical': 0.0006808896958692692, 'mean_word_length': 1.2766726943942135, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 24, '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': '3842213', 'n_tokens_mistral': 2380, 'n_tokens_neox': 2356, 'n_words': 554}