57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
StoreResponse,
|
|
OutstandingBalanceResponse,
|
|
StoreDashboardResponse,
|
|
StoreVisitHistoryItem,
|
|
} from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
// ─── Stores ───────────────────────────────────────────────────────────────────
|
|
|
|
export interface StoreBody {
|
|
routeId: string
|
|
ownerName?: string | null
|
|
contactNumber?: string | null
|
|
storeName: string
|
|
storeAddress: string
|
|
latitude: number
|
|
longitude: number
|
|
oneTimeAmount?: number
|
|
creditLimit?: number
|
|
segment?: string | null
|
|
isActive?: boolean
|
|
}
|
|
|
|
export interface StoreListParams extends PageParams {
|
|
routeId?: string
|
|
search?: string
|
|
}
|
|
|
|
export const stores = {
|
|
list: (params?: StoreListParams) =>
|
|
api.get<PaginatedResponse<StoreResponse>>('/stores', { params }).then(r => r.data),
|
|
|
|
get: (id: string) =>
|
|
api.get<StoreResponse>(`/stores/${id}`).then(r => r.data),
|
|
|
|
create: (body: StoreBody) =>
|
|
api.post<StoreResponse>('/stores', body).then(r => r.data),
|
|
|
|
update: (id: string, body: Partial<StoreBody>) =>
|
|
api.put<StoreResponse>(`/stores/${id}`, body).then(r => r.data),
|
|
|
|
updateStatus: (id: string, isActive: boolean) =>
|
|
api.patch<StoreResponse>(`/stores/${id}/status`, { isActive }).then(r => r.data),
|
|
|
|
outstandingBalance: (id: string) =>
|
|
api.get<OutstandingBalanceResponse>(`/stores/${id}/outstanding-balance`).then(r => r.data),
|
|
|
|
dashboard: (id: string, period?: string) =>
|
|
api.get<StoreDashboardResponse>(`/stores/${id}/dashboard`, { params: { period } }).then(r => r.data),
|
|
visitHistory: (id: string) =>
|
|
api.get<StoreVisitHistoryItem[]>(`/stores/${id}/visit-history`).then(r => r.data),
|
|
}
|