refactor backend and persist stock campaign queue
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m32s

This commit is contained in:
Cauê Faleiros
2026-05-27 15:00:23 -03:00
parent 6ba8219596
commit 8c2590c56a
25 changed files with 658 additions and 363 deletions

View File

@@ -1,4 +1,4 @@
import type { OrderData } from './types';
import type { OrderData, StockData } from './types';
const API_URL = import.meta.env.VITE_API_URL || '/api';
@@ -33,7 +33,7 @@ export const isAuthenticated = (): boolean => {
return !!localStorage.getItem('auth_token');
};
export const fetchStock = async (): Promise<any[]> => {
export const fetchStock = async (): Promise<StockData[]> => {
try {
const token = localStorage.getItem('auth_token');
const response = await fetch(`${API_URL}/stock`, {
@@ -47,7 +47,7 @@ export const fetchStock = async (): Promise<any[]> => {
}
if (!response.ok) return [];
return await response.json();
} catch (error) {
} catch {
return [];
}
};
@@ -89,7 +89,7 @@ export const parseOrderDate = (dateStr: string): Date => {
return isNaN(fallback.getTime()) ? new Date(0) : fallback;
};
export const exportToCSV = (data: any[], filename: string) => {
export const exportToCSV = (data: Record<string, unknown>[], filename: string) => {
if (!data || !data.length) return;
const headers = Object.keys(data[0]);
@@ -102,7 +102,7 @@ export const exportToCSV = (data: any[], filename: string) => {
for (const row of data) {
const values = headers.map(header => {
const val = row[header];
const escaped = ('' + val).replace(/"/g, '\\"');
const escaped = String(val ?? '').replace(/"/g, '""');
return `"${escaped}"`;
});
csvRows.push(values.join(','));