69 lines
2.3 KiB
TypeScript
69 lines
2.3 KiB
TypeScript
import { api } from '@/lib/api'
|
|
import type {
|
|
PaginatedResponse,
|
|
StoreResponse,
|
|
KycDocumentResponse,
|
|
OutstandingBalanceResponse,
|
|
StoreDashboardResponse,
|
|
StoreVisitHistoryItem,
|
|
KycStatus,
|
|
} from '@/types/api'
|
|
|
|
import type { PageParams } from './master'
|
|
|
|
// ─── Stores ───────────────────────────────────────────────────────────────────
|
|
|
|
export interface StoreBody {
|
|
routeId: string
|
|
ownerName: string
|
|
storeName: string
|
|
storeAddress: string
|
|
latitude: number
|
|
longitude: number
|
|
oneTimeAmount?: number
|
|
creditLimit?: number
|
|
segment?: string | null
|
|
isActive?: boolean
|
|
}
|
|
|
|
export interface StoreListParams extends PageParams {
|
|
routeId?: string
|
|
kycStatus?: KycStatus
|
|
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),
|
|
|
|
kycDocuments: (id: string) =>
|
|
api.get<KycDocumentResponse[]>(`/stores/${id}/kyc-documents`).then(r => r.data),
|
|
|
|
uploadKycDocument: (id: string, documentType: string, fileReference: string) =>
|
|
api.post<KycDocumentResponse>(`/stores/${id}/kyc-documents`, { documentType, fileReference }).then(r => r.data),
|
|
|
|
updateKycStatus: (id: string, kycStatus: KycStatus) =>
|
|
api.patch<StoreResponse>(`/stores/${id}/kyc-status`, { kycStatus }).then(r => r.data),
|
|
|
|
visitHistory: (id: string) =>
|
|
api.get<StoreVisitHistoryItem[]>(`/stores/${id}/visit-history`).then(r => r.data),
|
|
}
|