|
| 1 | +//Asyncrone request and Promise based HTTP client for the browser |
| 2 | +import axios from 'axios'; |
| 3 | + |
| 4 | +//Liste des actions |
| 5 | +import * from '../constants/actionTypes'; |
| 6 | + |
| 7 | +// Point d'entré de notre API |
| 8 | +const ROOT_URI = 'http://localhost:3000'; |
| 9 | + |
| 10 | +/*-------- Listes des action du domaine d'intervention -------------*/ |
| 11 | + |
| 12 | +export function fetchInterventions() { |
| 13 | + return dispatch => { |
| 14 | + dispatch({type:FETCH_INTERVENTIONS}); |
| 15 | + axios.get(`${ROOT_URI}/interventions`,{ |
| 16 | + headers: {accept: 'application/json'} |
| 17 | + }) |
| 18 | + .then(response =>{ |
| 19 | + dispatch(fetchInterventionsSuccess(response)); |
| 20 | + }) |
| 21 | + .catch(()=>{ |
| 22 | + dispatch(fetchCompetencesFailure("Liste des interventions est introuvable !")); |
| 23 | + }); |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +export function fetchInterventionsSuccess(Interventions){ |
| 28 | + return { |
| 29 | + type:FETCH_INTERVENTIONS_SUCCESS, |
| 30 | + payload:Interventions |
| 31 | + }; |
| 32 | +} |
| 33 | + |
| 34 | +export function fetchInterventionsFailure(error){ |
| 35 | + return { |
| 36 | + type:FETCH_INTERVENTIONS_FAILURE, |
| 37 | + payload:error |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +/*-------- Listes des action du domaine de competence -------------*/ |
| 42 | + |
| 43 | +export function fetchCompetences() { |
| 44 | + return dispatch => { |
| 45 | + dispatch({type:FETCH_COMPETENCES}); |
| 46 | + axios.get(`${ROOT_URI}/competences`,{ |
| 47 | + headers: {accept: 'application/json'} |
| 48 | + }) |
| 49 | + .then(response =>{ |
| 50 | + dispatch(fetchCompetencesSuccess(response)); |
| 51 | + }) |
| 52 | + .catch(()=>{ |
| 53 | + dispatch(fetchCompetencesFailure("Liste des compétences est introuvable !")); |
| 54 | + }); |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +export function fetchCompetencesSuccess(competences){ |
| 59 | + return { |
| 60 | + type:FETCH_COMPETENCES_SUCCESS, |
| 61 | + payload:competences |
| 62 | + }; |
| 63 | +} |
| 64 | + |
| 65 | +export function fetchCompetencesFailure(error){ |
| 66 | + return { |
| 67 | + type:FETCH_COMPETENCES_FAILURE, |
| 68 | + payload:error |
| 69 | + } |
| 70 | +} |
| 71 | + |
0 commit comments