[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 => {
|
---|
[08f82ec] | 12 | axios.post("/job-advertisements/add", jobAdvertisement)
|
---|
[19398ad] | 13 | .then(response => {
|
---|
| 14 | dispatch({
|
---|
| 15 | type: ADD_JOB_ADVERTISEMENT,
|
---|
| 16 | jobAdvertisement: response.data
|
---|
| 17 | })
|
---|
[08f82ec] | 18 | callback(true)
|
---|
[19398ad] | 19 | }).catch((error) => {
|
---|
[08f82ec] | 20 | console.error(error)
|
---|
| 21 | callback(false)
|
---|
[19398ad] | 22 | })
|
---|
| 23 | }
|
---|
| 24 | },
|
---|
| 25 | editJobAdvertisement: (jobAdvertisement, id, callback) => {
|
---|
| 26 | return dispatch => {
|
---|
| 27 | axios.put("/job-advertisements/edit/" + id, jobAdvertisement)
|
---|
| 28 | .then(response => {
|
---|
| 29 | dispatch({
|
---|
| 30 | type: EDIT_JOB_ADVERTISEMENT,
|
---|
| 31 | jobAdvertisement: response.data
|
---|
| 32 | })
|
---|
[08f82ec] | 33 | callback(true)
|
---|
[19398ad] | 34 | }).catch((error) => {
|
---|
[08f82ec] | 35 | console.error(error)
|
---|
| 36 | callback(false)
|
---|
[19398ad] | 37 | })
|
---|
| 38 | }
|
---|
| 39 | },
|
---|
| 40 | deleteJobAdvertisement: (id, callback) => {
|
---|
| 41 | return dispatch => {
|
---|
| 42 | axios.delete("/job-advertisements/delete/" + id)
|
---|
| 43 | .then(response => {
|
---|
| 44 | dispatch({
|
---|
| 45 | type: DELETE_JOB_ADVERTISEMENT,
|
---|
| 46 | id: id
|
---|
| 47 | })
|
---|
| 48 | callback(true)
|
---|
| 49 | }).catch(error => {
|
---|
[08f82ec] | 50 | console.error(error)
|
---|
| 51 | callback(false)
|
---|
[19398ad] | 52 | })
|
---|
| 53 |
|
---|
| 54 | }
|
---|
| 55 | },
|
---|
| 56 | fetchJobAdvertisementById: (id, callback) => {
|
---|
[28b3398] | 57 | axios.get("/job-advertisements/" + id)
|
---|
[19398ad] | 58 | .then(response => {
|
---|
| 59 | callback(true, response)
|
---|
| 60 | }).catch(error => {
|
---|
[28b3398] | 61 | callback(false, error)
|
---|
| 62 | })
|
---|
[19398ad] | 63 | },
|
---|
| 64 |
|
---|
| 65 | fetchJobAdvertisements: (callback) => {
|
---|
| 66 | return dispatch => {
|
---|
| 67 | axios.get("/job-advertisements/all")
|
---|
| 68 | .then(response => {
|
---|
| 69 | dispatch({
|
---|
| 70 | type: FETCH_JOB_ADVERTISEMENTS,
|
---|
| 71 | jobAdvertisements: response.data,
|
---|
| 72 | })
|
---|
| 73 | callback(true, response)
|
---|
| 74 | }).catch((error) => {
|
---|
| 75 | callback(false, error)
|
---|
| 76 | })
|
---|
| 77 | }
|
---|
| 78 | },
|
---|
[28b3398] | 79 | filterJobAdvertisements: (filter, callback) => {
|
---|
| 80 | axios.post("/job-advertisements/filtered", filter)
|
---|
| 81 | .then(response => {
|
---|
| 82 | callback(true, response)
|
---|
| 83 | }).catch((error) => {
|
---|
[08f82ec] | 84 | callback(false, error)
|
---|
| 85 | })
|
---|
[28b3398] | 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 |
|
---|
[08f82ec] | 105 | fetchJobAdvertisementsByRecruiterProfile: (recruiterId, callback) => {
|
---|
| 106 | return dispatch => {
|
---|
| 107 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
| 108 | axios.get("/job-advertisements/recruiter/" + recruiterId)
|
---|
| 109 | .then(response => {
|
---|
| 110 | callback(true, response)
|
---|
| 111 | }).catch((error) => {
|
---|
| 112 | callback(false, error)
|
---|
| 113 | })
|
---|
| 114 | }
|
---|
| 115 | },
|
---|
| 116 |
|
---|
[befb988] | 117 | filterJobAdvertisementsByRecruiter: (id, filter, callback) => {
|
---|
[28b3398] | 118 |
|
---|
| 119 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
[befb988] | 120 | axios.post("/job-advertisements/recruiter/" + id + "/filtered", filter)
|
---|
[28b3398] | 121 | .then(response => {
|
---|
| 122 | callback(true, response)
|
---|
| 123 | }).catch((error) => {
|
---|
| 124 | callback(false, error)
|
---|
| 125 | })
|
---|
| 126 |
|
---|
| 127 | },
|
---|
| 128 |
|
---|
[19398ad] | 129 | fetchRecruiterDetailsById: (id, callback) => {
|
---|
[08f82ec] | 130 | axios.get("/recruiter/" + id + "/info")
|
---|
[19398ad] | 131 | .then(response => {
|
---|
| 132 | callback(true, response)
|
---|
| 133 | }).catch(error => {
|
---|
| 134 | callback(false, error)
|
---|
| 135 | })
|
---|
| 136 | }
|
---|
| 137 | } |
---|