175 lines
5.4 KiB
TypeScript
175 lines
5.4 KiB
TypeScript
import { api, publicApi } from "./client";
|
|
import type {
|
|
AdventureOffering,
|
|
AdventureOfferingDetail,
|
|
AdventureStorefrontResponse,
|
|
AvailabilityResponse,
|
|
Booking,
|
|
CreateVendorAdventureRequest,
|
|
CreateVendorEquipmentRequest,
|
|
CustomerRegisterRequest,
|
|
EquipmentCategory,
|
|
EquipmentItem,
|
|
EquipmentItemDetail,
|
|
EquipmentStorefrontResponse,
|
|
ListingClick,
|
|
LoginRequest,
|
|
MarketingSummary,
|
|
TokenPair,
|
|
User,
|
|
VendorProfile,
|
|
VendorRegisterRequest,
|
|
} from "./types";
|
|
|
|
export async function login(body: LoginRequest): Promise<TokenPair> {
|
|
const { data } = await api.post<TokenPair>("/accounts/token/", body);
|
|
return data;
|
|
}
|
|
|
|
export async function fetchMe(): Promise<User> {
|
|
const { data } = await api.get<User>("/accounts/me/");
|
|
return data;
|
|
}
|
|
|
|
export async function registerVendor(body: VendorRegisterRequest): Promise<User> {
|
|
const { data } = await api.post<User>("/accounts/register/vendor/", body);
|
|
return data;
|
|
}
|
|
|
|
export async function registerCustomer(body: CustomerRegisterRequest): Promise<User> {
|
|
const { data } = await api.post<User>("/accounts/register/customer/", body);
|
|
return data;
|
|
}
|
|
|
|
export async function requestPasswordReset(email?: string): Promise<{ detail: string }> {
|
|
const { data } = await api.post<{ detail: string }>("/accounts/password/reset/request/", { email: email ?? "" });
|
|
return data;
|
|
}
|
|
|
|
export async function fetchVendorProfile(): Promise<VendorProfile> {
|
|
const { data } = await api.get<VendorProfile>("/accounts/vendor-profile/me/");
|
|
return data;
|
|
}
|
|
|
|
export async function patchVendorProfile(body: Partial<VendorProfile>): Promise<VendorProfile> {
|
|
const { data } = await api.patch<VendorProfile>("/accounts/vendor-profile/me/", body);
|
|
return data;
|
|
}
|
|
|
|
export type EquipmentListParams = {
|
|
category?: string;
|
|
location?: string;
|
|
vendor_slug?: string;
|
|
min_price?: string;
|
|
max_price?: string;
|
|
available_from?: string;
|
|
available_to?: string;
|
|
};
|
|
|
|
export async function listEquipmentItems(params?: EquipmentListParams): Promise<EquipmentItem[]> {
|
|
const { data } = await publicApi.get<EquipmentItem[]>("/equipment/items/", { params });
|
|
return data;
|
|
}
|
|
|
|
export async function getEquipmentItem(
|
|
publicId: string,
|
|
params?: Record<string, string>,
|
|
): Promise<EquipmentItemDetail> {
|
|
const { data } = await publicApi.get<EquipmentItemDetail>(`/equipment/items/${publicId}/`, { params });
|
|
return data;
|
|
}
|
|
|
|
export async function listVendorEquipment(): Promise<EquipmentItem[]> {
|
|
const { data } = await api.get<EquipmentItem[]>("/equipment/vendor/items/");
|
|
return data;
|
|
}
|
|
|
|
export async function listEquipmentCategories(): Promise<EquipmentCategory[]> {
|
|
const { data } = await publicApi.get<EquipmentCategory[]>("/equipment/categories/");
|
|
return data;
|
|
}
|
|
|
|
export async function createVendorEquipment(body: CreateVendorEquipmentRequest): Promise<EquipmentItem> {
|
|
const { data } = await api.post<EquipmentItem>("/equipment/vendor/items/", body);
|
|
return data;
|
|
}
|
|
|
|
export type AdventureListParams = EquipmentListParams;
|
|
|
|
export async function listAdventureOfferings(params?: AdventureListParams): Promise<AdventureOffering[]> {
|
|
const { data } = await publicApi.get<AdventureOffering[]>("/adventrues/offerings/", { params });
|
|
return data;
|
|
}
|
|
|
|
export async function getAdventureOffering(
|
|
publicId: string,
|
|
params?: Record<string, string>,
|
|
): Promise<AdventureOfferingDetail> {
|
|
const { data } = await publicApi.get<AdventureOfferingDetail>(`/adventrues/offerings/${publicId}/`, {
|
|
params,
|
|
});
|
|
return data;
|
|
}
|
|
|
|
export async function listVendorAdventures(): Promise<AdventureOffering[]> {
|
|
const { data } = await api.get<AdventureOffering[]>("/adventrues/vendor/offerings/");
|
|
return data;
|
|
}
|
|
|
|
export async function createVendorAdventure(body: CreateVendorAdventureRequest): Promise<AdventureOffering> {
|
|
const { data } = await api.post<AdventureOffering>("/adventrues/vendor/offerings/", body);
|
|
return data;
|
|
}
|
|
|
|
export async function getEquipmentStorefront(slug: string): Promise<EquipmentStorefrontResponse> {
|
|
const { data } = await publicApi.get<EquipmentStorefrontResponse>(`/equipment/storefront/${slug}/`);
|
|
return data;
|
|
}
|
|
|
|
export async function getAdventureStorefront(slug: string): Promise<AdventureStorefrontResponse> {
|
|
const { data } = await publicApi.get<AdventureStorefrontResponse>(`/adventrues/storefront/${slug}/`);
|
|
return data;
|
|
}
|
|
|
|
export async function checkAvailability(params: {
|
|
equipment_item_id?: number;
|
|
adventure_offering_id?: number;
|
|
starts_at: string;
|
|
ends_at: string;
|
|
}): Promise<AvailabilityResponse> {
|
|
const { data } = await api.get<AvailabilityResponse>("/booking/availability/", { params });
|
|
return data;
|
|
}
|
|
|
|
export async function listBookings(): Promise<Booking[]> {
|
|
const { data } = await api.get<Booking[]>("/booking/bookings/");
|
|
return data;
|
|
}
|
|
|
|
export async function getBooking(id: number): Promise<Booking> {
|
|
const { data } = await api.get<Booking>(`/booking/bookings/${id}/`);
|
|
return data;
|
|
}
|
|
|
|
export async function fetchVendorMarketingSummary(from: string, to: string): Promise<MarketingSummary> {
|
|
const { data } = await api.get<MarketingSummary>("/marketing/vendor/summary/", {
|
|
params: { from, to },
|
|
});
|
|
return data;
|
|
}
|
|
|
|
export async function fetchVendorListingClicks(
|
|
from: string,
|
|
to: string,
|
|
extra?: {
|
|
traffic_type?: "organic" | "marketing";
|
|
listing_type?: "equipment" | "adventure";
|
|
utm_campaign?: string;
|
|
},
|
|
): Promise<ListingClick[]> {
|
|
const { data } = await api.get<ListingClick[]>("/marketing/vendor/clicks/", {
|
|
params: { from, to, ...extra },
|
|
});
|
|
return data;
|
|
}
|