<commit_before>import Parse from './parseConfig';
import * as actionTypes from '../util/actionsTypes';
import * as notificationActions from './notification';

function requestPackages() {
  return {
    type: actionTypes.REQUEST_PACKAGES,
  };
}

function receivePackages(packages) {
  return {
    type: actionTypes.RECEIVE_PACKAGES,
    packages,
  };
}

function savePackageBegin() {
  return {
    type: actionTypes.SAVE_PACKAGE_BEGIN,
  };
}

function savePackageComplete(pkg) {
  return {
    type: actionTypes.SAVE_PACKAGE_COMPLETE,
    pkg,
  };
}

export function pickPackage(pkg) {
  return {
    type: actionTypes.PICK_PACKAGE,
    pkg,
  }
}

export function clearPickPackage() {
  return {
    type: actionTypes.CLEAR_PICK_PACKAGE,
  }
}

export function notificationUpdate(notificationContent, notificationClass) {
  return {
    type: actionTypes.OPEN_NOTIFICATION,
    notificationContent,
    notificationClass,
  }
}

function swippedCardStatus(status) {
  return {
    type: actionTypes.SWIPPED_CARD_STATUS,
    status,
  }
}

const mapper = o => o.toJSON();
const Package = Parse.Object.extend('Package');
const Employee = Parse.Object.extend('Employee');
const Vendor = Parse.Object.extend('Vendor');
const CardSwipeLog = Parse.Object.extend('CardSwipeLog');

export const fetchPackages = (searchToken = '') => (
  (dispatch) => {
    dispatch(requestPackages());
    let query = new Parse.Query(Package);
    if (searchToken.length > 0) {
      const ownerNameQuery = new Parse.Query(Employee);
      ownerNameQuery.contains('name', searchToken);

      const ownerEmailQuery = new Parse.Query(Employee);
      ownerEmailQuery.contains('email', searchToken);

      const compoundOwnerQuery = Parse.Query.or(ownerNameQuery, ownerEmailQuery);

      const packageIdQuery = new Parse.Query(Package);
      packageIdQuery.contains('packageId', searchToken);

      const ownerQuery = new Parse.Query(Package);
      ownerQuery.matchesQuery('owner', compoundOwnerQuery);

      query = Parse.Query.or(ownerQuery, packageIdQuery);
    }
    query.include('owner');
    query.include('vendor');
    query.descending("createdAt");
    query.find().then((result) => {
      const data = result.map(mapper);
      dispatch(receivePackages(data));<commit_msg>[Ashok/Vinay] Fix issue. Allow user to search package by packageId<commit_after>import Parse from './parseConfig';
import * as actionTypes from '../util/actionsTypes';
import * as notificationActions from './notification';

function requestPackages() {
  return {
    type: actionTypes.REQUEST_PACKAGES,
  };
}

function receivePackages(packages) {
  return {
    type: actionTypes.RECEIVE_PACKAGES,
    packages,
  };
}

function savePackageBegin() {
  return {
    type: actionTypes.SAVE_PACKAGE_BEGIN,
  };
}

function savePackageComplete(pkg) {
  return {
    type: actionTypes.SAVE_PACKAGE_COMPLETE,
    pkg,
  };
}

export function pickPackage(pkg) {
  return {
    type: actionTypes.PICK_PACKAGE,
    pkg,
  }
}

export function clearPickPackage() {
  return {
    type: actionTypes.CLEAR_PICK_PACKAGE,
  }
}

export function notificationUpdate(notificationContent, notificationClass) {
  return {
    type: actionTypes.OPEN_NOTIFICATION,
    notificationContent,
    notificationClass,
  }
}

function swippedCardStatus(status) {
  return {
    type: actionTypes.SWIPPED_CARD_STATUS,
    status,
  }
}

const mapper = o => o.toJSON();
const Package = Parse.Object.extend('Package');
const Employee = Parse.Object.extend('Employee');
const Vendor = Parse.Object.extend('Vendor');
const CardSwipeLog = Parse.Object.extend('CardSwipeLog');

export const fetchPackages = (searchToken = '') => (
  (dispatch) => {
    dispatch(requestPackages());
    let query = new Parse.Query(Package);
    if (searchToken.length > 0) {
      const ownerNameQuery = new Parse.Query(Employee);
      ownerNameQuery.contains('name', searchToken);

      const ownerEmailQuery = new Parse.Query(Employee);
      ownerEmailQuery.contains('email', searchToken);

      const compoundOwnerQuery = Parse.Query.or(ownerNameQuery, ownerEmailQuery);

      const packageIdQuery = new Parse.Query(Package);
      packageIdQuery.equalTo('packageId', Number(searchToken));

      const ownerQuery = new Parse.Query(Package);
      ownerQuery.matchesQuery('owner', compoundOwnerQuery);

      query = Parse.Query.or(ownerQuery, packageIdQuery);
    }
    query.include('owner');
    query.include('vendor');
    query.descending("createdAt");
    query.find().then((result) => {
      const data = result.map(mapper);
      dispatch(receivePackages(data));
{'fraction_non_alphanumeric': 0.12038244241634072, 'fraction_numerical': 0.000434593654932638, 'mean_word_length': 4.103104212860311, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '3680547', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1350, 'n_words': 272}