city.js 965 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { createCachedApi } from "./cacheService";
  2. const api = createCachedApi("city");
  3. export const getCity = async (id) => {
  4. const { data } = await api.get("/city/" + id);
  5. return data.payload;
  6. };
  7. export const getCities = async () => {
  8. const { data } = await api.get("/city");
  9. return data.payload;
  10. };
  11. export const getCityByState = async (stateId) => {
  12. const { data } = await api.get(`/city/state/${stateId}`);
  13. return data.payload;
  14. };
  15. export const getCityByCountry = async (countryId) => {
  16. const { data } = await api.get(`/city/country/${countryId}`);
  17. return data.payload;
  18. };
  19. export const createCity = async (city) => {
  20. const { data } = await api.post("/city", city);
  21. return data.payload;
  22. };
  23. export const updateCity = async (city, id) => {
  24. const { data } = await api.put(`/city/${id}`, city);
  25. return data.payload;
  26. };
  27. export const deleteCity = async (id) => {
  28. const { data } = await api.del(`/city/${id}`);
  29. return data.payload;
  30. };