110 lines
3.8 KiB
JavaScript
110 lines
3.8 KiB
JavaScript
import api from './apiClient';
|
|
|
|
// -----------------------------
|
|
// General API
|
|
// -----------------------------
|
|
export const generalAPI = {
|
|
// GET /api/v1/General/Currencies
|
|
async getCurrencies() {
|
|
try {
|
|
const res = await api.get('/api/v1/General/Currencies', { skipAuthRedirect: true });
|
|
// پاسخ به صورت array مستقیم است
|
|
return Array.isArray(res?.data) ? res?.data : [];
|
|
} catch (error) {
|
|
console.error('🔴 General API - getCurrencies error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// GET /api/v1/General/TimeZones
|
|
async getTimeZones() {
|
|
try {
|
|
const res = await api.get('/api/v1/General/TimeZones', { skipAuthRedirect: true });
|
|
// پاسخ به صورت { data: [...], statusCode: 200, ... } است
|
|
return res?.data?.data || [];
|
|
} catch (error) {
|
|
console.error('🔴 General API - getTimeZones error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// GET /api/v1/General/IssuerCapabilities
|
|
async getIssuerCapabilities() {
|
|
try {
|
|
const res = await api.get('/api/v1/General/IssuerCapabilities', { skipAuthRedirect: true });
|
|
// پاسخ به صورت { data: [...], statusCode: 200, ... } است
|
|
return res?.data?.data || [];
|
|
} catch (error) {
|
|
console.error('🔴 General API - getIssuerCapabilities error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// GET /api/v1/General/SearchUsersByEmail
|
|
async searchUsersByEmail(email) {
|
|
try {
|
|
const res = await api.get('/api/v1/General/SearchUsersByEmail', {
|
|
params: { email: email || '' },
|
|
skipAuthRedirect: true
|
|
});
|
|
// پاسخ به صورت { data: [...], statusCode: 200, ... } است
|
|
return res?.data?.data || [];
|
|
} catch (error) {
|
|
console.error('🔴 General API - searchUsersByEmail error:', error);
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// ========== System Configuration Voucher API ==========
|
|
|
|
// GET /api/v1/SystemConfiguration/Voucher
|
|
async getVoucherConfiguration() {
|
|
try {
|
|
console.log('🔵 General API - getVoucherConfiguration request');
|
|
const res = await api.get('/api/v1/SystemConfiguration/Voucher', {
|
|
skipAuthRedirect: true
|
|
});
|
|
console.log('🟢 General API - getVoucherConfiguration response:', res?.data);
|
|
// Response structure: { statusCode, isSuccess, code, message, errors, data: { expireInDays, refundUponVoucherExpiration, canPurchaseByAgentVouchers, canTopUpWithUserVouchers } }
|
|
return res?.data?.data || null;
|
|
} catch (error) {
|
|
console.error('🔴 General API - getVoucherConfiguration error:', {
|
|
status: error?.response?.status,
|
|
data: error?.response?.data,
|
|
error: error?.response?.data || error?.message
|
|
});
|
|
throw error;
|
|
}
|
|
},
|
|
|
|
// PUT /api/v1/SystemConfiguration/Voucher
|
|
async updateVoucherConfiguration(config) {
|
|
if (!config) {
|
|
throw new Error('Voucher configuration is required');
|
|
}
|
|
try {
|
|
const payload = {
|
|
expireInDays: Number(config.expireInDays) || 0,
|
|
refundUponVoucherExpiration: Boolean(config.refundUponVoucherExpiration),
|
|
canPurchaseByAgentVouchers: Boolean(config.canPurchaseByAgentVouchers),
|
|
canTopUpWithUserVouchers: Boolean(config.canTopUpWithUserVouchers)
|
|
};
|
|
console.log('🔵 General API - updateVoucherConfiguration request:', { payload });
|
|
const res = await api.put('/api/v1/SystemConfiguration/Voucher', payload, {
|
|
skipAuthRedirect: true
|
|
});
|
|
console.log('🟢 General API - updateVoucherConfiguration response:', res?.data);
|
|
return res?.data;
|
|
} catch (error) {
|
|
console.error('🔴 General API - updateVoucherConfiguration error:', {
|
|
payload: config,
|
|
status: error?.response?.status,
|
|
data: error?.response?.data,
|
|
error: error?.response?.data || error?.message
|
|
});
|
|
throw error;
|
|
}
|
|
},
|
|
};
|
|
|