67 lines
1.6 KiB
TypeScript
67 lines
1.6 KiB
TypeScript
import { api } from './client';
|
|
import type { BusinessService } from './types';
|
|
|
|
export type CreateBusinessServicePayload = {
|
|
businessId: string;
|
|
serviceTemplateId: string;
|
|
price: number;
|
|
durationMinutes?: number | null;
|
|
isActive?: boolean;
|
|
};
|
|
|
|
export type UpdateBusinessServicePayload = {
|
|
price?: number;
|
|
durationMinutes?: number | null;
|
|
isActive?: boolean;
|
|
loyaltyEnabled?: boolean;
|
|
loyaltyEveryN?: number | null;
|
|
};
|
|
|
|
export function fetchBusinessServices(
|
|
businessId: string,
|
|
options?: { activeOnly?: boolean },
|
|
) {
|
|
const search = new URLSearchParams({ businessId });
|
|
if (options?.activeOnly) {
|
|
search.set('isActive', 'true');
|
|
}
|
|
return api<BusinessService[]>(`/business-services?${search}`);
|
|
}
|
|
|
|
export function createBusinessService(payload: CreateBusinessServicePayload) {
|
|
return api<BusinessService>('/business-services', {
|
|
method: 'POST',
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export function updateBusinessService(id: string, payload: UpdateBusinessServicePayload) {
|
|
return api<BusinessService>(`/business-services/${id}`, {
|
|
method: 'PATCH',
|
|
body: JSON.stringify(payload),
|
|
});
|
|
}
|
|
|
|
export function deleteBusinessService(id: string) {
|
|
return api<{ success: true }>(`/business-services/${id}`, {
|
|
method: 'DELETE',
|
|
});
|
|
}
|
|
|
|
export type ClassPriceItem = {
|
|
classId: string;
|
|
price: number;
|
|
durationMinutes?: number | null;
|
|
isActive?: boolean;
|
|
};
|
|
|
|
export function setBusinessServiceClassPrices(
|
|
id: string,
|
|
prices: ClassPriceItem[],
|
|
) {
|
|
return api<BusinessService>(`/business-services/${id}/class-prices`, {
|
|
method: 'PUT',
|
|
body: JSON.stringify({ prices }),
|
|
});
|
|
}
|