state.js 837 B

123456789101112131415161718192021222324252627282930313233
  1. import { createCachedApi } from "./cacheService";
  2. const api = createCachedApi("state");
  3. export const getState = async (id) => {
  4. const { data } = await api.get("/state/" + id);
  5. return data.payload;
  6. }
  7. export const getStates = async () => {
  8. const { data } = await api.get("/state");
  9. return data.payload;
  10. }
  11. export const getStateByCountry = async (countryId) => {
  12. const { data } = await api.get(`/state/country/${countryId}`);
  13. return data.payload;
  14. }
  15. export const createState = async (state) => {
  16. const { data } = await api.post("/state", state);
  17. return data.payload;
  18. }
  19. export const updateState = async (state, id) => {
  20. const { data } = await api.put(`/state/${id}`, state);
  21. return data.payload;
  22. }
  23. export const deleteState = async (id) => {
  24. const { data } = await api.del(`/state/${id}`);
  25. return data.payload;
  26. }