added request to api
This commit is contained in:
@@ -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
@@ -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 };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
@@ -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 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user