65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import axios from 'axios';
|
|
import type { AxiosResponse } from 'axios';
|
|
import { NIFType } from '../service/api';
|
|
import { toast } from 'react-hot-toast';
|
|
|
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
|
|
class GeradorService {
|
|
static async GenerateNIF(type: string | null): Promise<any[]> {
|
|
try {
|
|
const response: AxiosResponse = await axios.get(API_URL + 'Generate/GenerateNIF',
|
|
{
|
|
params: {
|
|
type: type
|
|
}
|
|
});
|
|
return response.data;
|
|
} catch (error) {
|
|
|
|
toast.error('Error fetching NIF:' + error.message);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
static async ValidateNIF(nif: string | null): Promise<any[]> {
|
|
try {
|
|
const response: AxiosResponse = await axios.get(API_URL + 'Generate/ValidateNIF',
|
|
{
|
|
params: {
|
|
nif: nif
|
|
}
|
|
});
|
|
return response.data;
|
|
} catch (error) {
|
|
toast.error('Error fetching NIF:' + error);
|
|
|
|
console.error('Error fetching NIF:', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
static async GenerateNISS(): Promise<any[]> {
|
|
try {
|
|
|
|
const response: AxiosResponse = await axios.get(API_URL + 'Generate/GenerateNISS');
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error('Error fetching NIF:', error);
|
|
return [];
|
|
}
|
|
}
|
|
|
|
static async GenerateCC(): Promise<any[]> {
|
|
try {
|
|
|
|
const response: AxiosResponse = await axios.get(API_URL + 'Generate/GenerateCC');
|
|
return response.data;
|
|
} catch (error) {
|
|
console.error('Error fetching NIF:', error);
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
export default GeradorService; |