Advertisement
hikirangi

Untitled

Apr 19th, 2020
206
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 = this.resetTimeZone(from);
  6.     let toDate = this.resetTimeZone(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 => {
  31.       }).catch(error => {
  32.         resultError += `Error acquired on adding work item:\n${JSON.stringify(error.data.value)}\n`;
  33.       });
  34.       workItemDate.setDate(workItemDate.getDate() + 1);
  35.     } while (workItemDate.toString() !== toDate.toString());
  36.  
  37.     if (resultError === "") {
  38.       loadingAlert.isClosing = true;
  39.       this.setRange({from: null, to: null});
  40.       this.changeOption(null);
  41.       newAlerts.push({
  42.         type: Alert.Type.SUCCESS,
  43.         key: `${Date.now()}`,
  44.         message: `${'Отсутствие успешно отражено.'}`
  45.       });
  46.       this.setState({alerts: newAlerts});
  47.     } else {
  48.       loadingAlert.isClosing = true;
  49.       newAlerts.push({
  50.         type: Alert.Type.ERROR,
  51.         key: `${Date.now()}`,
  52.         message: `При треке отсутствия произошли следующие ошибки:${resultError}`
  53.       });
  54.       this.setState({alerts: newAlerts})
  55.     }
  56.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement