93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PriceListResponse,
|
|
PriceResolution,
|
|
SchemeResponse,
|
|
SchemeRuleType,
|
|
} from '@/types/api'
|
|
|
|
// ─── Price Lists ──────────────────────────────────────────────────────────────
|
|
|
|
export interface PriceListItemBody {
|
|
itemId: string
|
|
price: number
|
|
minPrice?: number | null
|
|
}
|
|
|
|
export interface PriceListBody {
|
|
name: string
|
|
regionId?: string | null
|
|
effectiveFrom: string
|
|
effectiveTo: string
|
|
isActive?: boolean
|
|
items: PriceListItemBody[]
|
|
}
|
|
|
|
export const priceLists = {
|
|
list: (params?: { regionId?: string }) =>
|
|
api.get<PriceListResponse[]>('/price-lists', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<PriceListResponse>(`/price-lists/${id}`).then(r => r.data),
|
|
|
|
create: (body: PriceListBody) =>
|
|
api.post<PriceListResponse>('/price-lists', body).then(r => r.data),
|
|
|
|
update: (id: string, body: Partial<PriceListBody>) =>
|
|
api.put<PriceListResponse>(`/price-lists/${id}`, body).then(r => r.data),
|
|
|
|
remove: (id: string) =>
|
|
api.delete(`/price-lists/${id}`),
|
|
|
|
upsertItem: (priceListId: string, sku: string, body: { price: number; minPrice?: number | null; retailPrice?: number | null; agencyMarginPercent?: number | null }) =>
|
|
api.put<PriceListResponse>(`/price-lists/${priceListId}/items/${encodeURIComponent(sku)}`, body).then(r => r.data),
|
|
|
|
removeItem: (priceListId: string, sku: string) =>
|
|
api.delete<PriceListResponse>(`/price-lists/${priceListId}/items/${encodeURIComponent(sku)}`).then(r => r.data),
|
|
|
|
resolve: (params: { itemId: string; storeId: string; saleDate: string }) =>
|
|
api.get<PriceResolution>('/price-lists/resolve', { params }).then(r => r.data),
|
|
}
|
|
|
|
// ─── Schemes ──────────────────────────────────────────────────────────────────
|
|
|
|
export interface BundleComponentBody {
|
|
itemId: string
|
|
qty: number
|
|
}
|
|
|
|
export interface SchemeBody {
|
|
name: string
|
|
ruleType: SchemeRuleType
|
|
ruleConfig?: string | null
|
|
triggerItemId?: string | null
|
|
triggerQty?: number
|
|
freeItemId?: string | null
|
|
freeQty?: number
|
|
bundleComponents?: BundleComponentBody[]
|
|
regionId?: string | null
|
|
eligibleSegment?: string | null
|
|
dateRangeFrom: string
|
|
dateRangeTo: string
|
|
agentLimitExempt?: boolean
|
|
baselineExpectedSales?: number
|
|
isActive?: boolean
|
|
}
|
|
|
|
export const schemes = {
|
|
list: (params?: { regionId?: string }) =>
|
|
api.get<SchemeResponse[]>('/schemes', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<SchemeResponse>(`/schemes/${id}`).then(r => r.data),
|
|
|
|
create: (body: SchemeBody) =>
|
|
api.post<SchemeResponse>('/schemes', body).then(r => r.data),
|
|
|
|
update: (id: string, body: Partial<SchemeBody>) =>
|
|
api.put<SchemeResponse>(`/schemes/${id}`, body).then(r => r.data),
|
|
|
|
remove: (id: string) =>
|
|
api.delete(`/schemes/${id}`),
|
|
}
|