coursefields.actions.ts 1 KB
Newer Older
1
import { COURSEFIELDS_RECEIVED, COURSEFIELDS_SELECTED_SAVE } from '../constants';
2 3 4 5 6 7 8 9 10 11 12
import { Injectable } from '@angular/core';
import { NgRedux } from 'ng2-redux';
import { IAppState } from '../store';
import { HelperDataService } from '../services/helper-data-service';

@Injectable()
export class CourseFieldsActions {
  constructor(
    private _ngRedux: NgRedux<IAppState>,
    private _hds: HelperDataService) {}

13
  getCourseFields = () => {
14 15 16 17 18 19 20 21 22 23 24
    const { courseFields } = this._ngRedux.getState();
    if (courseFields.size === 0) {
        return this._hds.getCourseFields().then(courseFields => {
            return this._ngRedux.dispatch({
                type: COURSEFIELDS_RECEIVED,
                payload: {
                    courseFields
                }
            });
        });
    }
25 26
  };

27 28 29 30 31 32 33 34 35
  saveCourseFieldsSelected = (courseFieldsSelected) => {
      return this._ngRedux.dispatch({
        type: COURSEFIELDS_SELECTED_SAVE,
        payload: {
          courseFieldsSelected
        }
      });
  };

36
}