- Add billing-usage feature module with types, API clients, hooks, and components - Create PlanCard, PlanSelector, SubscriptionStatusBadge, InvoiceList, UsageSummaryCard, CouponInput components - Add BillingPage, PlansPage, InvoicesPage, UsagePage - Update routes to include billing section Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
87 lines
2.7 KiB
TypeScript
87 lines
2.7 KiB
TypeScript
import { api } from '@services/api/axios-instance';
|
|
import type {
|
|
Coupon,
|
|
CreateCouponDto,
|
|
UpdateCouponDto,
|
|
CouponValidation,
|
|
CouponFilters,
|
|
CouponsResponse,
|
|
CouponStats,
|
|
CouponRedemption,
|
|
} from '../types';
|
|
|
|
const BASE_URL = '/api/v1/billing/coupons';
|
|
|
|
export const couponsApi = {
|
|
getAll: async (filters?: CouponFilters): Promise<CouponsResponse> => {
|
|
const params = new URLSearchParams();
|
|
if (filters?.search) params.append('search', filters.search);
|
|
if (filters?.discountType) params.append('discountType', filters.discountType);
|
|
if (filters?.isActive !== undefined) params.append('isActive', String(filters.isActive));
|
|
if (filters?.page) params.append('page', String(filters.page));
|
|
if (filters?.limit) params.append('limit', String(filters.limit));
|
|
if (filters?.sortBy) params.append('sortBy', filters.sortBy);
|
|
if (filters?.sortOrder) params.append('sortOrder', filters.sortOrder);
|
|
|
|
const response = await api.get<CouponsResponse>(`${BASE_URL}?${params.toString()}`);
|
|
return response.data;
|
|
},
|
|
|
|
getById: async (id: string): Promise<Coupon> => {
|
|
const response = await api.get<Coupon>(`${BASE_URL}/${id}`);
|
|
return response.data;
|
|
},
|
|
|
|
getByCode: async (code: string): Promise<Coupon> => {
|
|
const response = await api.get<Coupon>(`${BASE_URL}/code/${code}`);
|
|
return response.data;
|
|
},
|
|
|
|
create: async (data: CreateCouponDto): Promise<Coupon> => {
|
|
const response = await api.post<Coupon>(BASE_URL, data);
|
|
return response.data;
|
|
},
|
|
|
|
update: async (id: string, data: UpdateCouponDto): Promise<Coupon> => {
|
|
const response = await api.patch<Coupon>(`${BASE_URL}/${id}`, data);
|
|
return response.data;
|
|
},
|
|
|
|
delete: async (id: string): Promise<void> => {
|
|
await api.delete(`${BASE_URL}/${id}`);
|
|
},
|
|
|
|
validate: async (code: string, planId?: string, amount?: number): Promise<CouponValidation> => {
|
|
const response = await api.post<CouponValidation>(`${BASE_URL}/validate`, {
|
|
code,
|
|
planId,
|
|
amount,
|
|
});
|
|
return response.data;
|
|
},
|
|
|
|
activate: async (id: string): Promise<Coupon> => {
|
|
const response = await api.post<Coupon>(`${BASE_URL}/${id}/activate`);
|
|
return response.data;
|
|
},
|
|
|
|
deactivate: async (id: string): Promise<Coupon> => {
|
|
const response = await api.post<Coupon>(`${BASE_URL}/${id}/deactivate`);
|
|
return response.data;
|
|
},
|
|
|
|
getStats: async (): Promise<CouponStats> => {
|
|
const response = await api.get<CouponStats>(`${BASE_URL}/stats`);
|
|
return response.data;
|
|
},
|
|
|
|
getRedemptions: async (
|
|
couponId: string
|
|
): Promise<{ data: CouponRedemption[]; total: number }> => {
|
|
const response = await api.get<{ data: CouponRedemption[]; total: number }>(
|
|
`${BASE_URL}/${couponId}/redemptions`
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|