Skip to content

Instantly share code, notes, and snippets.

@cp-sumi-k
Last active June 27, 2022 04:21
Show Gist options
  • Save cp-sumi-k/aadda667184c11d5104e78d2d92a8bd8 to your computer and use it in GitHub Desktop.
Save cp-sumi-k/aadda667184c11d5104e78d2d92a8bd8 to your computer and use it in GitHub Desktop.
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