2026-05-26 17:29:35 +08:00
|
|
|
import { apiRequest } from './api.js'
|
|
|
|
|
|
|
|
|
|
function buildQuery(params = {}) {
|
|
|
|
|
const search = new URLSearchParams()
|
|
|
|
|
Object.entries(params || {}).forEach(([key, value]) => {
|
|
|
|
|
if (typeof value === 'undefined' || value === null || value === '') return
|
2026-05-29 14:11:06 +08:00
|
|
|
search.set(key === 'pageSize' ? 'page_size' : key, String(value))
|
2026-05-26 17:29:35 +08:00
|
|
|
})
|
|
|
|
|
const query = search.toString()
|
|
|
|
|
return query ? `?${query}` : ''
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchBudgetSummary(params = {}) {
|
|
|
|
|
return apiRequest(`/budgets/summary${buildQuery(params)}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function fetchBudgetAllocations(params = {}) {
|
|
|
|
|
return apiRequest(`/budgets/allocations${buildQuery(params)}`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createBudgetAllocation(payload = {}) {
|
|
|
|
|
return apiRequest('/budgets/allocations', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
body: JSON.stringify(payload)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-29 14:11:06 +08:00
|
|
|
export function fetchBudgetTransactions(allocationId, params = {}) {
|
|
|
|
|
const encodedId = encodeURIComponent(String(allocationId || '').trim())
|
|
|
|
|
return apiRequest(`/budgets/allocations/${encodedId}/transactions${buildQuery(params)}`)
|
2026-05-26 17:29:35 +08:00
|
|
|
}
|