hikirangi

Untitled

Apr 19th, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  addWorkItems = async (issueId, serviceId, workType, from, to) => {
  2.     let wstate = this;
  3.     const minutesADay = 8 * 60;
  4.     let dashboardApi = this.props.dashboardApi;
  5.     let workItemDate = new Date(Date.parse(from));
  6.     let toDate = new Date(Date.parse(to));
  7.     toDate.setDate(toDate.getDate() + 1);
  8.     let resultError = '';
  9.     let newAlerts = this.state.alerts;
  10.     let loadingAlert = {
  11.       type: Alert.Type.LOADING,
  12.       key: `${Date.now()}`,
  13.       message: `Идет трек отсутствия...`,
  14.       isClosing: false
  15.     };
  16.     newAlerts.push(loadingAlert);
  17.     this.setState({alerts: newAlerts});
  18.     do {
  19.       newAlerts.push({type: Alert.Type.WARNING, key: `${Date.now()}`, message: `${workItemDate}`});
  20.       wstate.setState({alerts: newAlerts});
  21.       await dashboardApi.fetch(serviceId, `rest/issue/${issueId}/timetracking/workitem`, {
  22.         method: 'POST',
  23.         body: {
  24.           date: Date.parse(workItemDate),
  25.           duration: minutesADay,
  26.           worktype: {
  27.             name: workType
  28.           }
  29.         }
  30.       }).then(workItem => {}).catch(error => {
  31.         resultError += `Error acquired on adding work item:\n${JSON.stringify(error.data.value)}\n`;
  32.       });
  33.       workItemDate.setDate(workItemDate.getDate() + 1);
  34.     } while (workItemDate.toString() !== toDate.toString());
  35.  
  36.     if (resultError === "") {
  37.       loadingAlert.isClosing = true;
  38.       this.setRange({from: null, to: null});
  39.       this.changeOption(null);
  40.       newAlerts.push({
  41.         type: Alert.Type.SUCCESS,
  42.         key: `${Date.now()}`,
  43.         message: `${'Отсутствие успешно отражено.'}`
  44.       });
  45.       this.setState({alerts: newAlerts});
  46.     } else {
  47.       loadingAlert.isClosing = true;
  48.       newAlerts.push({
  49.         type: Alert.Type.ERROR,
  50.         key: `${Date.now()}`,
  51.         message: `При треке отсутствия произошли следующие ошибки:${resultError}`
  52.       });
  53.       this.setState({alerts: newAlerts})
  54.     }
  55.   };
Advertisement
Add Comment
Please, Sign In to add comment