[javascript] gavno

Viewer

  1. const fetchGetProfile = () => dispatch => {
  2.   return new Promise(resolve => {
  3.     dispatch({ type: FETCH_REQUEST })
  4.  
  5.     ServiceApi.getProfile()
  6.       .then(response => {
  7.         const { success, body: {
  8.           children,
  9.           locations,
  10.           contracts,
  11.           user,
  12.           contract_acceptance_needed,
  13.           contract_waiting_acceptance
  14.         } } = response.data;
  15.  
  16.         if (success) {
  17.  
  18.           let blocked_diary = true;
  19.           let blocked_booking = true;
  20.  
  21.           const filtedLocations = locations.filter(item => {
  22.             let LocationHasContract = contracts.filter(=> i.location_id === item.id)[0]
  23.             return LocationHasContract && item
  24.           })
  25.  
  26.           const filtedContracts = contracts.filter(item => {
  27.             let paramHasContract = filtedLocations.filter(=> i.id === item.location_id)[0];
  28.             return paramHasContract && item
  29.           })
  30.  
  31.           const filtedChildren = children.filter(item => {
  32.             let childHasContract = filtedContracts.filter(=> i.child_id === item.id)[0]
  33.             return childHasContract && item
  34.           })
  35.  
  36.           const contractsList = filtedContracts.filter(item => item.archive === false)
  37.             .map(item => {
  38.               const contract_child_name = children.filter(child => child.id === item.child_id)[0].normal_name;
  39.               const currentLocation = locations.filter(location => location.id === item.location_id);
  40.               const locationOptions = currentLocation.map(item => {
  41.                 let haveParamHistory = item.features.findIndex(loc => loc === "parents_login_child_history");
  42.                 let haveParamAdvanced = item.features.findIndex(loc => loc === "parents_login_advanced");
  43.  
  44.                 if (haveParamHistory >= 0 && blocked_diary) { blocked_diary = false };
  45.                 if (haveParamAdvanced >= 0 && blocked_booking) { blocked_booking = false };
  46.  
  47.                 return {
  48.                   contract_location_name: item.name,
  49.                   parents_login_child_history: haveParamHistory >= 0 ? true : false,
  50.                   parents_login_advanced: haveParamAdvanced >= 0 ? true : false
  51.                 }
  52.               })
  53.  
  54.               return ({
  55.                 ...item,
  56.                 contract_child_name: contract_child_name,
  57.                 ...locationOptions[0],
  58.               })
  59.             })
  60.  
  61.           const archiveContracts = contracts.filter(item => item.archive)
  62.             .map(item => {
  63.               const contract_child_name = children.filter(child => child.id === item.child_id)[0].normal_name;
  64.               const currentLocation = locations.filter(location => location.id === item.location_id);
  65.               const locationOptions = currentLocation.map(item => {
  66.                 let haveParamHistory = item.features.findIndex(loc => loc === "parents_login_child_history");
  67.                 let haveParamAdvanced = item.features.findIndex(loc => loc === "parents_login_advanced");
  68.  
  69.                 if (haveParamHistory >= 0 && blocked_diary) { blocked_diary = false };
  70.                 if (haveParamAdvanced >= 0 && blocked_booking) { blocked_booking = false };
  71.  
  72.                 return {
  73.                   contract_location_name: item.name,
  74.                   parents_login_child_history: haveParamHistory >= 0 ? true : false,
  75.                   parents_login_advanced: haveParamAdvanced >= 0 ? true : false
  76.                 }
  77.               })
  78.  
  79.               return ({
  80.                 ...item,
  81.                 contract_child_name: contract_child_name,
  82.                 ...locationOptions[0],
  83.               })
  84.             })
  85.  
  86.  
  87.           dispatch({
  88.             type: FETCH_SUCCESS,
  89.             payload: {
  90.               children: filtedChildren,
  91.               locations: filtedLocations,
  92.               contracts: contractsList,
  93.               archive_contracts: archiveContracts,
  94.               user,
  95.               blocked_diary,
  96.               blocked_booking,
  97.               contract_acceptance_needed,
  98.               contract_waiting_acceptance,
  99.             }
  100.           })
  101.  
  102.           resolve({ language: user.language, contract_acceptance_needed })
  103.         } else {
  104.           dispatch({ type: FETCH_FAILURE });
  105.           logger.error('fetchGetProfile', error);
  106.         }
  107.  
  108.       })
  109.       .catch(error => {
  110.         dispatch({ type: FETCH_FAILURE })
  111.         logger.error('fetchGetProfile', error);
  112.       })
  113.   })
  114. }

Editor

You can edit this paste and save as new:


File Description
  • gavno
  • Paste Code
  • 01 Mar-2021
  • 4.39 Kb
You can Share it: