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,
|
---|
6 | FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER, FILTER_JOB_ADVERTISEMENTS
|
---|
7 | } from "../actionTypes";
|
---|
8 |
|
---|
9 | export const JobAdvertisementActions = {
|
---|
10 | addJobAdvertisement: (jobAdvertisement, callback) => {
|
---|
11 | return dispatch => {
|
---|
12 | axios.post("/job-advertisements/add", jobAdvertisement)
|
---|
13 | .then(response => {
|
---|
14 | dispatch({
|
---|
15 | type: ADD_JOB_ADVERTISEMENT,
|
---|
16 | jobAdvertisement: response.data
|
---|
17 | })
|
---|
18 | callback(true)
|
---|
19 | }).catch((error) => {
|
---|
20 | console.error(error)
|
---|
21 | callback(false)
|
---|
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 | })
|
---|
33 | callback(true)
|
---|
34 | }).catch((error) => {
|
---|
35 | console.error(error)
|
---|
36 | callback(false)
|
---|
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 => {
|
---|
50 | console.error(error)
|
---|
51 | callback(false)
|
---|
52 | })
|
---|
53 |
|
---|
54 | }
|
---|
55 | },
|
---|
56 | fetchJobAdvertisementById: (id, callback) => {
|
---|
57 | axios.get("/job-advertisements/" + id)
|
---|
58 | .then(response => {
|
---|
59 | callback(true, response)
|
---|
60 | }).catch(error => {
|
---|
61 | callback(false, error)
|
---|
62 | })
|
---|
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 | },
|
---|
79 | filterJobAdvertisements: (filter, callback) => {
|
---|
80 | axios.post("/job-advertisements/filtered", filter)
|
---|
81 | .then(response => {
|
---|
82 | callback(true, response)
|
---|
83 | }).catch((error) => {
|
---|
84 | callback(false, error)
|
---|
85 | })
|
---|
86 |
|
---|
87 | },
|
---|
88 |
|
---|
89 | fetchJobAdvertisementsByRecruiter: (recruiterId, callback) => {
|
---|
90 | return dispatch => {
|
---|
91 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
92 | axios.get("/job-advertisements/recruiter/" + recruiterId)
|
---|
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 |
|
---|
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 |
|
---|
117 | filterJobAdvertisementsByRecruiter: (id, filter, callback) => {
|
---|
118 |
|
---|
119 | let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
|
---|
120 | axios.post("/job-advertisements/recruiter/" + id + "/filtered", filter)
|
---|
121 | .then(response => {
|
---|
122 | callback(true, response)
|
---|
123 | }).catch((error) => {
|
---|
124 | callback(false, error)
|
---|
125 | })
|
---|
126 |
|
---|
127 | },
|
---|
128 |
|
---|
129 | fetchRecruiterDetailsById: (id, callback) => {
|
---|
130 | axios.get("/recruiter/" + id + "/info")
|
---|
131 | .then(response => {
|
---|
132 | callback(true, response)
|
---|
133 | }).catch(error => {
|
---|
134 | callback(false, error)
|
---|
135 | })
|
---|
136 | }
|
---|
137 | } |
---|