chore: build

This commit is contained in:
2026-06-14 18:09:44 +02:00
parent 3a0f725159
commit 6d4e0862ff
45 changed files with 3745 additions and 873 deletions
+123 -31
View File
@@ -1,4 +1,5 @@
import apiClient, { API_BASE_URL } from "./client";
import apiClient from "./client";
import { API_BASE_URL } from "./client";
import type {
AuthResponse,
ClientResponse,
@@ -52,6 +53,72 @@ export const logoutAdmin = async (): Promise<void> => {
}
};
export interface StatsSummary {
total_orders: number;
total_revenue: number;
peak_weekday: string;
top_product: string;
avg_per_day: number;
}
export interface WeekdayStat {
weekday: string;
count: number;
}
export interface DayStat {
day: string;
label: string;
count: number;
}
export interface DayRevenueStat {
day: string;
label: string;
revenue: number;
}
export interface HourStat {
hour: number;
label: string;
count: number;
revenue: number;
}
export interface ProductStat {
product_id: number;
name: string;
quantity: number;
order_count: number;
revenue: number;
category: string;
category_color: string;
}
export interface QuantityStat {
quantity: number;
order_count: number;
total_sold: number;
revenue: number;
}
export interface ProductQuantityBreakdown {
product_id: number;
name: string;
category_color: string;
total_orders: number;
quantities: QuantityStat[];
}
export interface AdminStats {
summary: StatsSummary;
by_weekday: WeekdayStat[];
by_day_30: DayStat[];
by_day_revenue: DayRevenueStat[];
by_hour: HourStat[];
top_products: ProductStat[];
by_quantity: ProductQuantityBreakdown[];
}
export const getAdminStats = async (): Promise<AdminStats> => {
const { data } = await apiClient.get(`${V2}/admin/protected/stats`);
return data;
};
export const getAllClients = async (): Promise<ClientResponse[]> => {
const { data } = await apiClient.get(`${V2}/admin/protected/all/clients`);
return data.clients || [];
@@ -84,9 +151,6 @@ export const updateUserByAdmin = async (
return { success: true, message: data.message, user: data.user };
};
// ============================================
// COMMANDES
export const getAllCommands = async (status?: string, username?: string) => {
let url = `${V2}/admin/protected/orders`;
const params: string[] = [];
@@ -171,8 +235,11 @@ export const updateCommandAddress = async (
export const validateCommand = async (commandId: number) => {
const { data } = await apiClient.post(
`${V2}/admin/protected/orders/${commandId}/force-validate`,
{ command_id: commandId },
);
return { success: true, message: data.message };
const validated = (data.validated ?? []) as { command_id: number; points_awarded: number }[];
const points = validated.find((v) => v.command_id === commandId)?.points_awarded ?? 0;
return { success: true, points_awarded: points, validated_count: data.validated_count ?? 0 };
};
export const proposeAddressChangeAdmin = async (
@@ -197,31 +264,22 @@ export const notifyClientToDescend = async (commandId: number) => {
};
};
export const confirmReceptionAdmin = async (commandId: number) => {
const { data } = await apiClient.post(
`${V2}/admin/protected/orders/${commandId}/confirm-reception`,
);
return {
success: true,
message: data.message,
points_earned: data.points_earned,
client_username: data.client_username,
};
};
// ============================================
// LIVREURS
// ============================================
export const getAvailableDeliveryPersons = async () => {
const { data } = await apiClient.get(
`${V2}/admin/protected/delivery-persons`,
);
return {
success: true,
livreurs: data.livreurs || [],
count: data.count || 0,
};
try {
const { data } = await apiClient.get(
`${V2}/admin/protected/delivery-persons`,
);
return {
success: true,
livreurs: data.livreurs || [],
count: data.count || 0,
};
} catch {
return { success: false, livreurs: [], count: 0 };
}
};
export const assignDeliveryPerson = async (
@@ -370,10 +428,6 @@ export const getDeliverymanLocationForCommand = async (commandId: number) => {
}
};
// ============================================
// PRODUITS
// ============================================
export const getAllProductsAdmin = async (): Promise<{
success: boolean;
data: Product[];
@@ -445,7 +499,7 @@ export const createUserByAdmin = async (data: {
role: string;
}) => {
const { data: res } = await apiClient.post(
`${V2}/admin/auth/register`,
`${V2}/admin/protected/users`,
data,
);
return {
@@ -710,6 +764,20 @@ export const deleteProductMediaAdmin = async (
return { success: true, message: data.message };
};
export const activateProductPrice = async (priceId: number) => {
const { data } = await apiClient.post(
`${V2}/admin/protected/active/product/price/${priceId}`,
);
return { success: true, message: data.message };
};
export const deactivateProductPrice = async (priceId: number) => {
const { data } = await apiClient.post(
`${V2}/admin/protected/desactive/product/price/${priceId}`,
);
return { success: true, message: data.message };
};
// ============================================
// ADDRESSES
// ============================================
@@ -849,6 +917,26 @@ export interface PointsTier {
points: number;
}
export interface RewardCategoryConfig {
category: string;
all_products: boolean;
product_ids: number[];
}
export interface RewardItem {
product_id: number;
quantity: number;
price: number;
}
export interface PointsReward {
threshold: number;
type: "free_product" | "half_price_product" | "custom";
description: string;
category_configs: RewardCategoryConfig[];
reward_items: RewardItem[];
}
export interface PointsPool {
key: string;
name: string;
@@ -947,6 +1035,7 @@ export interface AppSettings {
penalty_tiers: PenaltyTier[];
points_enabled: boolean;
points_pools: PointsPool[];
points_reward?: PointsReward | null;
referral_enabled: boolean;
delivery_schedule: DeliverySchedule;
postal_zones: PostalZone[];
@@ -958,7 +1047,10 @@ export interface AppSettings {
telegram_bot_token: string;
telegram_bot_username: string;
telegram_notifications_enabled: boolean;
telegram_2fa_enabled: boolean;
delivery_mode: DeliveryModeConfig;
shop_name: string;
contact_telegram: string;
}
export const getSettings = async (): Promise<{