56 lines
3.1 KiB
TypeScript
56 lines
3.1 KiB
TypeScript
import { api } from "./client";
|
|
import type {
|
|
Favorite,
|
|
FavoriteTag,
|
|
MessageResponse,
|
|
PaginatedResponse,
|
|
PriceHistory,
|
|
PriceMonitor,
|
|
} from "../types";
|
|
|
|
export const favoriteApi = {
|
|
list: (params?: { tag_id?: number, page?: number }) =>
|
|
api.get<PaginatedResponse<Favorite>>("/favorites/", { params }).then((r) => r.data),
|
|
exportCsv: () => api.get<Blob>("/favorites/export/", { responseType: "blob" }).then((r) => r.data),
|
|
get: (id: number) => api.get<Favorite>(`/favorites/${id}`).then((r) => r.data),
|
|
check: (productId: number, websiteId: number) =>
|
|
api.get<{ is_favorited: boolean, favorite_id: number | null }>(
|
|
"/favorites/check/",
|
|
{ params: { product_id: productId, website_id: websiteId } }
|
|
).then((r) => r.data),
|
|
add: (data: { product_id: number, website_id: number }) =>
|
|
api.post<Favorite>("/favorites/", data).then((r) => r.data),
|
|
remove: (id: number) => api.delete<MessageResponse>(`/favorites/${id}`).then((r) => r.data),
|
|
|
|
listTags: () => api.get<FavoriteTag[]>("/favorites/tags/").then((r) => r.data),
|
|
createTag: (data: { name: string; color?: string; description?: string }) =>
|
|
api.post<FavoriteTag>("/favorites/tags/", data).then((r) => r.data),
|
|
updateTag: (id: number, data: { name?: string; color?: string; description?: string }) =>
|
|
api.patch<FavoriteTag>(`/favorites/tags/${id}`, data).then((r) => r.data),
|
|
deleteTag: (id: number) => api.delete<MessageResponse>(`/favorites/tags/${id}`).then((r) => r.data),
|
|
addTagToFavorite: (favoriteId: number, tagId: number) =>
|
|
api.post<MessageResponse>(`/favorites/${favoriteId}/tags/`, { tag_id: tagId }).then((r) => r.data),
|
|
removeTagFromFavorite: (favoriteId: number, tagId: number) =>
|
|
api.delete<MessageResponse>(`/favorites/${favoriteId}/tags/${tagId}`).then((r) => r.data),
|
|
|
|
getMonitor: (favoriteId: number) =>
|
|
api.get<PriceMonitor | null>(`/favorites/${favoriteId}/monitor/`).then((r) => r.data),
|
|
createMonitor: (favoriteId: number, data: { target_price?: string; is_active?: boolean; notify_enabled?: boolean; notify_on_target?: boolean }) =>
|
|
api.post<PriceMonitor>(`/favorites/${favoriteId}/monitor/`, data).then((r) => r.data),
|
|
updateMonitor: (favoriteId: number, data: { target_price?: string; is_active?: boolean; notify_enabled?: boolean; notify_on_target?: boolean }) =>
|
|
api.patch<PriceMonitor>(`/favorites/${favoriteId}/monitor/`, data).then((r) => r.data),
|
|
deleteMonitor: (favoriteId: number) =>
|
|
api.delete<MessageResponse>(`/favorites/${favoriteId}/monitor/`).then((r) => r.data),
|
|
getMonitorHistory: (favoriteId: number, page?: number) =>
|
|
api.get<PaginatedResponse<PriceHistory>>(
|
|
`/favorites/${favoriteId}/monitor/history/`,
|
|
{ params: { page } }
|
|
).then((r) => r.data),
|
|
recordPrice: (favoriteId: number, price: string) =>
|
|
api.post<PriceHistory>(`/favorites/${favoriteId}/monitor/record/`, { price }).then((r) => r.data),
|
|
refreshMonitor: (favoriteId: number) =>
|
|
api.post<PriceMonitor>(`/favorites/${favoriteId}/monitor/refresh/`).then((r) => r.data),
|
|
listAllMonitors: (page?: number) =>
|
|
api.get<PaginatedResponse<PriceMonitor>>("/favorites/monitors/all/", { params: { page } }).then((r) => r.data),
|
|
};
|