49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { apiClient } from '@/lib/api-client'
|
|
import type { Deal, DealStage, DealStatus } from '@/types/crm'
|
|
|
|
export interface DealFilters {
|
|
page?: number
|
|
pageSize?: number
|
|
status?: DealStatus[]
|
|
stage?: DealStage | null
|
|
ownerId?: number
|
|
minAmount?: number | null
|
|
maxAmount?: number | null
|
|
orderBy?: 'created_at' | 'amount' | 'updated_at'
|
|
order?: 'asc' | 'desc'
|
|
}
|
|
|
|
export interface DealPayload {
|
|
contact_id: number
|
|
title: string
|
|
amount?: number | string | null
|
|
currency?: string | null
|
|
owner_id?: number | null
|
|
}
|
|
|
|
export interface DealUpdatePayload {
|
|
status?: DealStatus
|
|
stage?: DealStage
|
|
amount?: number | string | null
|
|
currency?: string | null
|
|
}
|
|
|
|
const mapFilters = (filters?: DealFilters) => ({
|
|
page: filters?.page,
|
|
page_size: filters?.pageSize,
|
|
status: filters?.status,
|
|
stage: filters?.stage ?? undefined,
|
|
owner_id: filters?.ownerId,
|
|
min_amount: filters?.minAmount ?? undefined,
|
|
max_amount: filters?.maxAmount ?? undefined,
|
|
order_by: filters?.orderBy,
|
|
order: filters?.order,
|
|
})
|
|
|
|
export const listDeals = (filters?: DealFilters) => apiClient.get<Deal[]>('/deals/', { params: mapFilters(filters) })
|
|
|
|
export const createDeal = (payload: DealPayload) => apiClient.post<Deal, DealPayload>('/deals/', payload)
|
|
|
|
export const updateDeal = (dealId: number, payload: DealUpdatePayload) =>
|
|
apiClient.patch<Deal, DealUpdatePayload>(`/deals/${dealId}`, payload)
|