|
|
@@ -1,22 +1,13 @@
|
|
|
-import axios from 'axios';
|
|
|
+import axios, { isAxiosError } from 'axios';
|
|
|
import { Alert } from 'react-native';
|
|
|
import * as SecureStore from 'expo-secure-store';
|
|
|
-import { forgetPasswordFormData } from '../types/signup';
|
|
|
-import { CustomerData } from '../types/signUpFormData';
|
|
|
-
|
|
|
+import {apiClient} from './requets'
|
|
|
+import { ChargingDetails, ElectricityPrice } from './type/chargeStationType';
|
|
|
class ChargeStationService {
|
|
|
- private apiUrl: string;
|
|
|
-
|
|
|
- constructor() {
|
|
|
- this.apiUrl = process.env.EXPO_PUBLIC_API_URL;
|
|
|
- if (!this.apiUrl) {
|
|
|
- throw new Error('API URL is not defined in environment variables');
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
async fetchCarBrand() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/public/client/car/brand`);
|
|
|
+ const response = await apiClient.instance.get(`/public/client/car/brand`);
|
|
|
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
@@ -24,7 +15,7 @@ class ChargeStationService {
|
|
|
console.log('invalid response');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -35,7 +26,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getCarImage(filename: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/public/image?filename=${filename}`);
|
|
|
+ const response: any = await apiClient.instance.get(`/public/image?filename=${filename}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.url;
|
|
|
} else {
|
|
|
@@ -45,11 +36,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getUserCars() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/customer/car/all`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/customer/car/all`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
} else {
|
|
|
@@ -59,11 +46,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getUserDefaultCars() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/customer/car/all?queryDefault=true`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/customer/car/all?queryDefault=true`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
// console.log(response.data.data);
|
|
|
return response.data;
|
|
|
@@ -74,8 +57,8 @@ class ChargeStationService {
|
|
|
|
|
|
async getReservationWithSize(size: number) {
|
|
|
try {
|
|
|
- const response = await axios.get(
|
|
|
- `${this.apiUrl}/clients/reservation/connectors/2405311022116801000/${size}`,
|
|
|
+ const response = await apiClient.instance.get(
|
|
|
+ `/clients/reservation/connectors/2405311022116801000/${size}`,
|
|
|
{
|
|
|
headers: {
|
|
|
Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
@@ -91,8 +74,8 @@ class ChargeStationService {
|
|
|
|
|
|
async addCar(licensePlate: string, carBrandFk: string, carTypeFk: string, isDefault: boolean) {
|
|
|
try {
|
|
|
- const response = await axios.post(
|
|
|
- `${this.apiUrl}/clients/customer/car`,
|
|
|
+ const response = await apiClient.instance.post(
|
|
|
+ `/clients/customer/car`,
|
|
|
{
|
|
|
licensePlate: licensePlate,
|
|
|
carBrandFk: carBrandFk,
|
|
|
@@ -111,7 +94,7 @@ class ChargeStationService {
|
|
|
return false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('error:', error.response?.data?.message || error.message);
|
|
|
return false;
|
|
|
} else {
|
|
|
@@ -121,29 +104,20 @@ class ChargeStationService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async deleteCar(carID) {
|
|
|
+ async deleteCar(carID: string) {
|
|
|
try {
|
|
|
- const response = await axios.delete(`${this.apiUrl}/clients/customer/car?carId=${carID}`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.delete(`/clients/customer/car?carId=${carID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return true;
|
|
|
} else {
|
|
|
}
|
|
|
} catch (error) {}
|
|
|
}
|
|
|
- async setDefaultCar(carID) {
|
|
|
+ async setDefaultCar(carID: string) {
|
|
|
try {
|
|
|
- const response = await axios.put(
|
|
|
- `${this.apiUrl}/clients/customer/car/default?carId=${carID}`,
|
|
|
+ const response = await apiClient.instance.put(
|
|
|
+ `/clients/customer/car/default?carId=${carID}`,
|
|
|
{},
|
|
|
- {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- }
|
|
|
);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return true;
|
|
|
@@ -154,11 +128,7 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchPriceForCharging() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/info`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
}
|
|
|
@@ -167,7 +137,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getCurrentPrice() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/promotion/price?id=2405311022116801000`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/price?id=2405311022116801000`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.price;
|
|
|
} else {
|
|
|
@@ -175,7 +145,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Error getting current price:', error);
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Response data:', error.response?.data);
|
|
|
console.error('Response status:', error.response?.status);
|
|
|
}
|
|
|
@@ -184,7 +154,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
async getOriginalPrice() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/promotion/price?id=2405311022116801000`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/price?id=2405311022116801000`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.originalPrice;
|
|
|
} else {
|
|
|
@@ -192,7 +162,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Error getting original price:', error);
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Response data:', error.response?.data);
|
|
|
console.error('Response status:', error.response?.status);
|
|
|
}
|
|
|
@@ -202,16 +172,11 @@ class ChargeStationService {
|
|
|
|
|
|
async NewfetchAvailableConnectors() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/local/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/local/info`);
|
|
|
if (response.status === 200 && response.data.code === 200) {
|
|
|
return response.data.data.map((station: any) => {
|
|
|
// const snapshotData = JSON.parse(station.snapshot);
|
|
|
const snapshotData = station.snapshot;
|
|
|
-
|
|
|
const availableConnectors = station?.Equipments?.reduce((count: number, equipment: any) => {
|
|
|
return (
|
|
|
count +
|
|
|
@@ -225,7 +190,8 @@ class ChargeStationService {
|
|
|
address: snapshotData.Address,
|
|
|
image: station?.image,
|
|
|
stationLng: snapshotData.StationLng,
|
|
|
- stationLat: snapshotData.StationLat
|
|
|
+ stationLat: snapshotData.StationLat,
|
|
|
+ pricemodel_id: station.pricemodel_id,
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
@@ -238,19 +204,14 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchAvailableConnectors(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(
|
|
|
- `${this.apiUrl}/clients/chargestations/resources/status?StationIDs=${stationID}`,
|
|
|
- {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- }
|
|
|
+ const response = await apiClient.instance.get(
|
|
|
+ `/clients/chargestations/resources/status?StationIDs=${stationID}`,
|
|
|
);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
const stationStatusInfos = response.data.data.StationStatusInfos;
|
|
|
if (stationStatusInfos && stationStatusInfos.length > 0) {
|
|
|
const availableConnectors = stationStatusInfos[0].ConnectorStatusInfos.filter(
|
|
|
- (connector) => connector.Status === 2
|
|
|
+ (connector: any) => connector.Status === 2
|
|
|
).length;
|
|
|
return availableConnectors;
|
|
|
}
|
|
|
@@ -262,14 +223,10 @@ class ChargeStationService {
|
|
|
}
|
|
|
async fetchChargeStations() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/info`);
|
|
|
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
- return response.data.data.map((station, index) => {
|
|
|
+ return response.data.data.map((station: any) => {
|
|
|
const { Address, StationName, StationID, StationLng, StationLat } = station.snapshot;
|
|
|
const image = station.image;
|
|
|
|
|
|
@@ -285,7 +242,7 @@ class ChargeStationService {
|
|
|
} else {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -296,11 +253,7 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchChargeStationIdByScannedConnectorId(scannedConnectorId: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/info`);
|
|
|
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
const station = response.data.data.find((station: any) =>
|
|
|
@@ -314,7 +267,7 @@ class ChargeStationService {
|
|
|
return false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -325,11 +278,7 @@ class ChargeStationService {
|
|
|
|
|
|
async noImagefetchChargeStationIdByScannedConnectorId(scannedConnectorId: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/local/simple/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/local/simple/info`);
|
|
|
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
const station = response.data.data.find((station: any) =>
|
|
|
@@ -343,7 +292,7 @@ class ChargeStationService {
|
|
|
return false;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -354,17 +303,13 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchAllChargeStations() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/chargestations/resources/info`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/chargestations/resources/info`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.data;
|
|
|
} else {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -375,14 +320,14 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchChargeStationPrice(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/promotion/price?id=${stationID}`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/price?id=${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.price;
|
|
|
} else {
|
|
|
console.log('invalid response');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -393,19 +338,15 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchAvailableDates(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/reservation/connectors/${stationID}`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/connectors/${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
- const dates = response.data.map((i) => i.date);
|
|
|
+ const dates = response.data.map((i: any) => i.date);
|
|
|
return dates;
|
|
|
} else {
|
|
|
console.log('invalid response');
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -416,21 +357,17 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchAvailableTimeSlots(stationID: string, targetDate: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/reservation/connectors/${stationID}`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/connectors/${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
- const times = response.data.find((i) => i.date === targetDate);
|
|
|
+ const times = response.data.find((i: any) => i.date === targetDate);
|
|
|
if (times) {
|
|
|
- const availableTimeSlots = times.range.map((i) => i.start);
|
|
|
+ const availableTimeSlots = times.range.map((i: any) => i.start);
|
|
|
return availableTimeSlots;
|
|
|
}
|
|
|
} else {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Login error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred:', error);
|
|
|
@@ -441,11 +378,7 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchSpecificChargeStation(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/reservation/connectors/${stationID}`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/connectors/${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
} else {
|
|
|
@@ -458,13 +391,8 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchOngoingChargingData(format_order_id: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(
|
|
|
- `${this.apiUrl}/clients/chargestations/resources/equip/status?StartChargeSeq=${format_order_id}`,
|
|
|
- {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- }
|
|
|
+ const response = await apiClient.instance.get(
|
|
|
+ `/clients/chargestations/resources/equip/status?StartChargeSeq=${format_order_id}`,
|
|
|
);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
@@ -478,11 +406,7 @@ class ChargeStationService {
|
|
|
|
|
|
async fetchReservationHistories() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/reservation/all`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/all`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
|
|
|
return response.data;
|
|
|
@@ -501,11 +425,7 @@ class ChargeStationService {
|
|
|
StartBalance: number;
|
|
|
}) {
|
|
|
try {
|
|
|
- const response = await axios.put(`${this.apiUrl}/clients/chargestations/resources/charge/start`, payload, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.put(`/clients/chargestations/resources/charge/start`, payload);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
} else {
|
|
|
@@ -519,11 +439,7 @@ class ChargeStationService {
|
|
|
async stopCharging(payload: { StartChargeSeq: string; ConnectorID: string }) {
|
|
|
try {
|
|
|
console.log('stpo charge initialized');
|
|
|
- const response = await axios.put(`${this.apiUrl}/clients/chargestations/resources/charge/stop`, payload, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.put(`/clients/chargestations/resources/charge/stop`, payload);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
console.log('stopCharging success', response);
|
|
|
return response.data;
|
|
|
@@ -537,11 +453,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getTodayReservation() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/reservation/today`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/today`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
// console.log('getTodayReservation response.data: ', response.data);
|
|
|
return response.data;
|
|
|
@@ -555,15 +467,8 @@ class ChargeStationService {
|
|
|
|
|
|
async getProcessedImageUrl(filename: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/public/image?filename=${filename}`, {
|
|
|
- // const response = await axios.get(`${this.apiUrl}/public/image?filename=BENZ-EQA.png`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`/public/image?filename=${filename}`)
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
- // console.log('i am getProcessedImageUrl s resposne', response.data.url);
|
|
|
-
|
|
|
return response.data.url;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
@@ -574,11 +479,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getProcessedCarImageUrl(filename: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`http://ftp.hkmgt.com/cdn/public/file/crazycharge/${filename}`, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.get(`http://ftp.hkmgt.com/cdn/public/file/crazycharge/${filename}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.detail;
|
|
|
}
|
|
|
@@ -590,11 +491,7 @@ class ChargeStationService {
|
|
|
|
|
|
async payPenalty(penaltyData: any) {
|
|
|
try {
|
|
|
- const response = await axios.post(`${this.apiUrl}/clients/pay/penalty`, penaltyData, {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- });
|
|
|
+ const response = await apiClient.instance.post(`/clients/pay/penalty`, penaltyData);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
} else {
|
|
|
@@ -602,7 +499,7 @@ class ChargeStationService {
|
|
|
return null;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Penalty payment error:', error.response?.data?.message || error.message);
|
|
|
} else {
|
|
|
console.error('An unexpected error occurred during penalty payment:', error);
|
|
|
@@ -613,7 +510,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getAdvertise() {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/advertise/advertise`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/advertise/advertise`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data;
|
|
|
} else {
|
|
|
@@ -626,7 +523,7 @@ class ChargeStationService {
|
|
|
|
|
|
async getCurrentPriceInPay(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/promotion/price?id=${stationID}`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/price?id=${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.price;
|
|
|
} else {
|
|
|
@@ -634,7 +531,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Error getting current price:', error);
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Response data:', error.response?.data);
|
|
|
console.error('Response status:', error.response?.status);
|
|
|
}
|
|
|
@@ -643,7 +540,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
async getOriginalPriceInPay(stationID: string) {
|
|
|
try {
|
|
|
- const response = await axios.get(`${this.apiUrl}/clients/promotion/price?id=${stationID}`);
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/price?id=${stationID}`);
|
|
|
if (response.status === 200 || response.status === 201) {
|
|
|
return response.data.originalPrice;
|
|
|
// throw new Error(`Unexpected response status: ${response.status}`);
|
|
|
@@ -652,7 +549,7 @@ class ChargeStationService {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Error getting original price:', error);
|
|
|
- if (axios.isAxiosError(error)) {
|
|
|
+ if (isAxiosError(error)) {
|
|
|
console.error('Response data:', error.response?.data);
|
|
|
console.error('Response status:', error.response?.status);
|
|
|
}
|
|
|
@@ -661,17 +558,12 @@ class ChargeStationService {
|
|
|
}
|
|
|
async validateCoupon(couponRecords: string[], orderAmount: number) {
|
|
|
try {
|
|
|
- const response = await axios.post(
|
|
|
- `${this.apiUrl}/clients/coupon/valid`,
|
|
|
+ const response = await apiClient.instance.post(
|
|
|
+ `/clients/coupon/valid`,
|
|
|
{
|
|
|
couponRecords: couponRecords,
|
|
|
orderAmount: orderAmount
|
|
|
},
|
|
|
- {
|
|
|
- headers: {
|
|
|
- Authorization: `Bearer ${await SecureStore.getItemAsync('accessToken')}`
|
|
|
- }
|
|
|
- }
|
|
|
);
|
|
|
if (response.data.is_valid === true) {
|
|
|
return true;
|
|
|
@@ -682,5 +574,30 @@ class ChargeStationService {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+ async fetchChargingDetails(recordID: string) {
|
|
|
+ try {
|
|
|
+ const response = await apiClient.instance.get(`/clients/reservation/getRecordById/${recordID}`);
|
|
|
+ if (response.status === 200 || response.status === 201) {
|
|
|
+ return response.data as ChargingDetails [];
|
|
|
+ } else {
|
|
|
+ return []
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ async fetchElectricityPrice(id: string) {
|
|
|
+ try {
|
|
|
+ const response = await apiClient.instance.get(`/clients/promotion/business_hourGroup?pricemodel_id=${id}`);
|
|
|
+ if (response.status === 200 || response.status === 201) {
|
|
|
+ return response.data as ElectricityPrice [];
|
|
|
+ } else {
|
|
|
+ return [] as ElectricityPrice []
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
export const chargeStationService = new ChargeStationService();
|