62 lines
1.7 KiB
JavaScript
62 lines
1.7 KiB
JavaScript
import api from './apiClient';
|
|
|
|
// -----------------------------
|
|
// City API
|
|
// -----------------------------
|
|
export const cityAPI = {
|
|
// GET /api/v1/City (with pagination and filters)
|
|
async list(params = {}) {
|
|
const { currentPage = 1, pageSize = 10, countryId, provinceId, ...otherParams } = params;
|
|
const requestParams = { currentPage, pageSize, ...otherParams };
|
|
|
|
// اگر countryId یا provinceId وجود دارد، آنها را به params اضافه کن
|
|
if (countryId) {
|
|
requestParams.countryId = countryId;
|
|
}
|
|
if (provinceId) {
|
|
requestParams.provinceId = provinceId;
|
|
}
|
|
|
|
const res = await api.get('/api/v1/City', {
|
|
params: requestParams,
|
|
skipAuthRedirect: true
|
|
});
|
|
|
|
// پاسخ به صورت { data: { data: [...], filterSummary: {...} } } است
|
|
return res?.data?.data?.data || [];
|
|
},
|
|
|
|
// POST /api/v1/City
|
|
async create(city) {
|
|
const payload = {
|
|
ProvinceId: city?.provinceId || '',
|
|
CityName: String(city?.cityName || ''),
|
|
};
|
|
const res = await api.post('/api/v1/City', payload, { skipAuthRedirect: true });
|
|
return res?.data;
|
|
},
|
|
|
|
// PUT /api/v1/City/{cityId}
|
|
async update(cityId, city) {
|
|
if (!cityId) {
|
|
throw new Error('City ID is required');
|
|
}
|
|
const payload = {
|
|
ProvinceId: city?.provinceId || '',
|
|
CityName: String(city?.cityName || '').trim(),
|
|
};
|
|
try {
|
|
const res = await api.put(`/api/v1/City/${encodeURIComponent(cityId)}`, payload, { skipAuthRedirect: true });
|
|
return res?.data;
|
|
} catch (error) {
|
|
console.error('City API Update Error:', {
|
|
cityId,
|
|
payload,
|
|
error: error?.response?.data || error?.message || error
|
|
});
|
|
throw error;
|
|
}
|
|
},
|
|
};
|
|
|