Last active
June 27, 2022 04:21
-
-
Save cp-sumi-k/aadda667184c11d5104e78d2d92a8bd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from "axios"; | |
const defaultState = { | |
jobs: null, | |
jobById: null, | |
jobsError: null, | |
}; | |
const getters = { | |
jobs: (state) => state.jobs, | |
jobById: (state) => state.jobById, | |
jobsError: (state) => state.jobsError, | |
} | |
const actions = { | |
getJobs({ commit }) { | |
return new Promise((resolve, reject) => { | |
axios | |
.get(BASE_API_URL + "/api/careers") | |
.then((response) => { | |
commit("SET_JOBS", response.data); | |
resolve(response); | |
}) | |
.catch((error) => { | |
commit("SET_JOBS_ERROR", error); | |
reject(error); | |
}); | |
}); | |
}, | |
getJobById({ commit }, data) { | |
return new Promise((resolve, reject) => { | |
axios | |
.get(BASE_API_URL + "/api/careers/" + data.jobId) | |
.then((response) => { | |
commit("SET_JOB_BY_ID", response); | |
resolve(response); | |
}) | |
.catch((error) => { | |
commit("SET_JOBS_ERROR", error); | |
reject(error); | |
}); | |
}); | |
}, | |
} | |
const mutations = { | |
SET_JOBS: (state, jobs) => { | |
state.jobs = jobs; | |
state.jobsError = null; | |
}, | |
SET_JOB_BY_ID: (state, data) => { | |
state.jobById = data.job; | |
state.jobsError = null; | |
}, | |
SET_JOBS_ERROR: (state, jobsError) => { | |
state.jobsError = jobsError; | |
}, | |
} | |
export default { | |
state: defaultState, | |
getters, | |
actions, | |
mutations, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment