added request to api

This commit is contained in:
2025-09-19 17:20:05 -06:00
parent 33060b5dbb
commit ca67be2de3
14 changed files with 296 additions and 254 deletions
+23
View File
@@ -0,0 +1,23 @@
import axios from "axios";
import Cookies from "js-cookie";
import { envConfig } from "./config";
const apiClient = axios.create({
baseURL: envConfig.apiUrl,
headers: {
"Content-Type": "application/json",
},
});
apiClient.interceptors.request.use((config) => {
const token = Cookies.get("token");
console.log(token)
if (token) {
if (config.headers && "set" in config.headers) {
config.headers.set("Authorization", `Bearer ${token}`);
}
}
return config;
});
export default apiClient;
+13 -10
View File
@@ -2,14 +2,17 @@ import axios from "axios";
import { envConfig } from "./config";
export async function loginUser(usuario: string, password: string) {
try {
const response = await axios.post(`${envConfig.apiUrl}/user`, { usuario, password });
return response.data;
} catch (error: any) {
const msg =
error.response?.data?.message ||
error.message ||
"Error desconocido en el login";
return { error: msg };
}
try {
const response = await axios.post(`${envConfig.apiUrl}/user`, {
usuario,
password,
});
return response.data;
} catch (error: any) {
const msg =
error.response?.data?.message ||
error.message ||
"Error desconocido en el login";
return { error: msg };
}
}
+14
View File
@@ -0,0 +1,14 @@
import apiClient from "@/app/lib/apiClient";
export async function PostImpressions(data: any) {
try {
const response = await apiClient.post("/operations", data);
return response.data;
} catch (error: any) {
const msg =
error.response?.data?.error ||
error.message ||
"Error desconocido al cobrar impresión";
return { error: msg };
}
}
+15
View File
@@ -0,0 +1,15 @@
import apiClient from "./apiClient";
export async function PostReceipt(data: any) {
try {
const response = await apiClient.post("/recibo", data);
console.log(response.data);
return response.data;
} catch (error: any) {
const msg =
error.response?.data?.message ||
error.message ||
"Error desconocido al crear recibo";
return { error: msg };
}
}
-18
View File
@@ -1,18 +0,0 @@
import axios from "axios";
import { envConfig } from "./config";
export async function PostReceipt(usuario: string, password: string) {
try {
const response = await axios.post(`${envConfig.apiUrl}/operations`, {
usuario,
password,
});
return response.data;
} catch (error: any) {
const msg =
error.response?.data?.message ||
error.message ||
"Error desconocido en el guardado del Recibo";
return { error: msg };
}
}