[19398ad] | 1 | import axios from "../../axios/axiosInstance";
|
---|
| 2 | import {
|
---|
| 3 | ADD_JOB_ADVERTISEMENT,
|
---|
| 4 | CURRENT_USER, DELETE_JOB_ADVERTISEMENT, EDIT_JOB_ADVERTISEMENT,
|
---|
| 5 | FETCH_JOB_ADVERTISEMENTS,
|
---|
[28b3398] | 6 | FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER, FILTER_JOB_ADVERTISEMENTS
|
---|
[19398ad] | 7 | } from "../actionTypes";
|
---|
| 8 |
|
---|
| 9 | export const JobAdvertisementActions = {
|
---|
| 10 | addJobAdvertisement: (jobAdvertisement, callback) => {
|
---|
| 11 | return dispatch => {
|
---|
[28b3398] | 12 | axios.post("/job-advertisements/add", jobAdvertisement, {
|
---|
| 13 | headers: {
|
---|
| 14 | 'Content-Type': 'application/json'
|
---|
| 15 | },
|
---|
| 16 | })
|
---|
[19398ad] | 17 | .then(response => {
|
---|
| 18 | dispatch({
|
---|
| 19 | type: ADD_JOB_ADVERTISEMENT,
|
---|
| 20 | jobAdvertisement: response.data
|
---|
| 21 | })
|
---|
| 22 | callback(true, response)
|
---|
| 23 | }).catch((error) => {
|
---|
| 24 | callback(false, error)
|
---|
| 25 | })
|
---|
| 26 | }
|
---|
| 27 | },
|
---|
| 28 | editJobAdvertisement: (jobAdvertisement, id, callback) => {
|
---|
| 29 | return dispatch => {
|
---|
| 30 | axios.put("/job-advertisements/edit/" + id, jobAdvertisement)
|
---|
| 31 | .then(response => {
|
---|
| 32 | dispatch({
|
---|
| 33 | type: EDIT_JOB_ADVERTISEMENT,
|
---|
| 34 | jobAdvertisement: response.data
|
---|
| 35 | })
|
---|
| 36 | callback(true, response)
|
---|
| 37 | }).catch((error) => {
|
---|
| 38 | callback(false, error)
|
---|
| 39 | })
|
---|
| 40 | }
|
---|
| 41 | },
|
---|
| 42 | deleteJobAdvertisement: (id, callback) => {
|
---|
| 43 | return dispatch => {
|
---|
| 44 | axios.delete("/job-advertisements/delete/" + id)
|
---|
| 45 | .then(response => {
|
---|
| 46 | dispatch({
|
---|
| 47 | type: DELETE_JOB_ADVERTISEMENT,
|
---|
| 48 | id: id
|
---|
| 49 | })
|
---|
| 50 | callback(true)
|
---|
| 51 | }).catch(error => {
|
---|
| 52 | callback(false, error)
|
---|
| 53 | })
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 | },
|
---|
| 57 | fetchJobAdvertisementById: (id, callback) => {
|
---|
[28b3398] | 58 | axios.get("/job-advertisements/" + id)
|
---|
[19398ad] | 59 | .then(response => {
|
---|
| 60 | callback(true, response)
|
---|
| 61 | }).catch(error => {
|
---|
[28b3398] | 62 | callback(false, error)
|
---|
| 63 | })
|
---|
[19398ad] | 64 | },
|
---|
| 65 |
|
---|
| 66 | fetchJobAdvertisements: (callback) => {
|
---|
| 67 | return dispatch => {
|
---|
| 68 | axios.get("/job-advertisements/all")
|
---|
| 69 | .then(response => {
|
---|
| 70 | dispatch({
|
---|
| 71 | type: FETCH_JOB_ADVERTISEMENTS,
|
---|
| 72 | jobAdvertisements: response.data,
|
---|
| 73 | })
|
---|
| 74 | callback(true, response)
|
---|
| 75 | }).catch((error) => {
|
---|
| 76 | callback(false, error)
|
---|
| 77 | })
|
---|
| 78 | }
|
---|
| 79 | },
|
---|
[28b3398] | 80 | filterJobAdvertisements: (filter, callback) => {
|
---|
| 81 | axios.post("/job-advertisements/filtered", filter)
|
---|
| 82 | .then(response => {
|
---|
| 83 | callback(true, response)
|
---|
| 84 | }).catch((error) => {
|
---|
| 85 | callback(false, error) })
|
---|
| 86 |
|
---|
| 87 | },
|
---|
[19398ad] | 88 |
|
---|
[befb988] | 89 | fetchJobAdvertisementsByRecruiter: (recruiterId, callback) => {
|
---|
[19398ad] | 90 | return dispatch => {
|
---|
| 91 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
[befb988] | 92 | axios.get("/job-advertisements/recruiter/" + recruiterId)
|
---|
[19398ad] | 93 | .then(response => {
|
---|
| 94 | dispatch({
|
---|
| 95 | type: FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER,
|
---|
| 96 | jobAdvertisementsByRecruiter: response.data,
|
---|
| 97 | })
|
---|
| 98 | callback(true, response)
|
---|
| 99 | }).catch((error) => {
|
---|
| 100 | callback(false, error)
|
---|
| 101 | })
|
---|
| 102 | }
|
---|
| 103 | },
|
---|
| 104 |
|
---|
[befb988] | 105 | filterJobAdvertisementsByRecruiter: (id, filter, callback) => {
|
---|
[28b3398] | 106 |
|
---|
| 107 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
[befb988] | 108 | axios.post("/job-advertisements/recruiter/" + id + "/filtered", filter)
|
---|
[28b3398] | 109 | .then(response => {
|
---|
| 110 | callback(true, response)
|
---|
| 111 | }).catch((error) => {
|
---|
| 112 | callback(false, error)
|
---|
| 113 | })
|
---|
| 114 |
|
---|
| 115 | },
|
---|
| 116 |
|
---|
[19398ad] | 117 | fetchRecruiterDetailsById: (id, callback) => {
|
---|
[befb988] | 118 | axios.get("/recruiter/"+id+"/info")
|
---|
[19398ad] | 119 | .then(response => {
|
---|
| 120 | callback(true, response)
|
---|
| 121 | }).catch(error => {
|
---|
| 122 | callback(false, error)
|
---|
| 123 | })
|
---|
| 124 | }
|
---|
| 125 | } |
---|