source: jobvista-frontend/src/redux/actions/jobAdvertisementActions.js@ 19398ad

main
Last change on this file since 19398ad was 19398ad, checked in by 223021 <daniel.ilievski.2@…>, 4 months ago

Implemented backend and frontend CRUD operations for job advertisements

  • Property mode set to 100644
File size: 3.4 KB
Line 
1import axios from "../../axios/axiosInstance";
2import {
3 ADD_JOB_ADVERTISEMENT,
4 CURRENT_USER, DELETE_JOB_ADVERTISEMENT, EDIT_JOB_ADVERTISEMENT,
5 FETCH_JOB_ADVERTISEMENTS,
6 FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER
7} from "../actionTypes";
8
9export 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, response)
19 }).catch((error) => {
20 callback(false, error)
21 })
22 }
23 },
24 editJobAdvertisement: (jobAdvertisement, id, callback) => {
25 return dispatch => {
26 axios.put("/job-advertisements/edit/" + id, jobAdvertisement)
27 .then(response => {
28 dispatch({
29 type: EDIT_JOB_ADVERTISEMENT,
30 jobAdvertisement: response.data
31 })
32 callback(true, response)
33 }).catch((error) => {
34 callback(false, error)
35 })
36 }
37 },
38 deleteJobAdvertisement: (id, callback) => {
39 return dispatch => {
40 axios.delete("/job-advertisements/delete/" + id)
41 .then(response => {
42 dispatch({
43 type: DELETE_JOB_ADVERTISEMENT,
44 id: id
45 })
46 callback(true)
47 }).catch(error => {
48 callback(false, error)
49 })
50
51 }
52 },
53 fetchJobAdvertisementById: (id, callback) => {
54 axios.get("/job-advertisements/view/" + id)
55 .then(response => {
56 callback(true, response)
57 }).catch(error => {
58 callback(false, error)
59 })
60 },
61
62 fetchJobAdvertisements: (callback) => {
63 return dispatch => {
64 axios.get("/job-advertisements/all")
65 .then(response => {
66 dispatch({
67 type: FETCH_JOB_ADVERTISEMENTS,
68 jobAdvertisements: response.data,
69 })
70 callback(true, response)
71 }).catch((error) => {
72 callback(false, error)
73 })
74 }
75 },
76
77 fetchJobAdvertisementsByRecruiter: (id, callback) => {
78 return dispatch => {
79 let currentUser = JSON.parse(localStorage.getItem(CURRENT_USER));
80 axios.get("/job-advertisements/recruiter/" + currentUser.id)
81 .then(response => {
82 dispatch({
83 type: FETCH_JOB_ADVERTISEMENTS_BY_RECRUITER,
84 jobAdvertisementsByRecruiter: response.data,
85 })
86 callback(true, response)
87 }).catch((error) => {
88 console.log("ERROR")
89 callback(false, error)
90 })
91 }
92 },
93
94 fetchRecruiterDetailsById: (id, callback) => {
95 axios.get("/recruiter/info/" + id)
96 .then(response => {
97 callback(true, response)
98 }).catch(error => {
99 callback(false, error)
100 })
101 }
102}
Note: See TracBrowser for help on using the repository browser.