// Get all budgets for current month
const response = await fetch(
'https://api.yourfinanceapp.com/api/budgets',
{
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
}
);
const budgets = await response.json();
// Find specific budget by ID
const budgetId = '550e8400-e29b-41d4-a716-446655440000';
const budget = findBudgetById(budgets, budgetId);
function findBudgetById(budgets, id) {
for (const budget of budgets) {
if (budget.id === id) return budget;
// Recursively search children
const found = findBudgetById(budget.children, id);
if (found) return found;
}
return null;
}
// Access status fields
console.log({
spent: budget.spent,
remaining: budget.remaining,
status: budget.status,
percentage: budget.percentage
});
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"categoryId": "660e8400-e29b-41d4-a716-446655440001",
"categoryName": "Food & Dining",
"categoryColor": "#FF6B6B",
"categoryIcon": "Utensils",
"amount": 50000,
"spent": 42000,
"directSpent": 30000,
"remaining": 8000,
"percentage": 84,
"status": "WARNING",
"children": []
}
Get detailed status for a specific budget including spending and remaining amounts
// Get all budgets for current month
const response = await fetch(
'https://api.yourfinanceapp.com/api/budgets',
{
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
}
);
const budgets = await response.json();
// Find specific budget by ID
const budgetId = '550e8400-e29b-41d4-a716-446655440000';
const budget = findBudgetById(budgets, budgetId);
function findBudgetById(budgets, id) {
for (const budget of budgets) {
if (budget.id === id) return budget;
// Recursively search children
const found = findBudgetById(budget.children, id);
if (found) return found;
}
return null;
}
// Access status fields
console.log({
spent: budget.spent,
remaining: budget.remaining,
status: budget.status,
percentage: budget.percentage
});
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"categoryId": "660e8400-e29b-41d4-a716-446655440001",
"categoryName": "Food & Dining",
"categoryColor": "#FF6B6B",
"categoryIcon": "Utensils",
"amount": 50000,
"spent": 42000,
"directSpent": 30000,
"remaining": 8000,
"percentage": 84,
"status": "WARNING",
"children": []
}
/api/budgets list endpoint already provides comprehensive status information for all budgets, including:
GET /api/budgets?month=X&year=Yid in the responseif (limit === 0) {
status = 'UNBUDGETED';
} else {
percentage = Math.round((spent / limit) * 100);
if (percentage >= 100) {
status = 'EXCEEDED';
} else if (percentage >= 80) {
status = 'WARNING';
} else {
status = 'OK';
}
}
// Get all budgets for current month
const response = await fetch(
'https://api.yourfinanceapp.com/api/budgets',
{
headers: {
'Authorization': 'Bearer YOUR_TOKEN'
}
}
);
const budgets = await response.json();
// Find specific budget by ID
const budgetId = '550e8400-e29b-41d4-a716-446655440000';
const budget = findBudgetById(budgets, budgetId);
function findBudgetById(budgets, id) {
for (const budget of budgets) {
if (budget.id === id) return budget;
// Recursively search children
const found = findBudgetById(budget.children, id);
if (found) return found;
}
return null;
}
// Access status fields
console.log({
spent: budget.spent,
remaining: budget.remaining,
status: budget.status,
percentage: budget.percentage
});
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"categoryId": "660e8400-e29b-41d4-a716-446655440001",
"categoryName": "Food & Dining",
"categoryColor": "#FF6B6B",
"categoryIcon": "Utensils",
"amount": 50000,
"spent": 42000,
"directSpent": 30000,
"remaining": 8000,
"percentage": 84,
"status": "WARNING",
"children": []
}
@Get(':id/status')
async getStatus(
@Param('id') id: string,
@CurrentUser('id') userId: string,
) {
const budget = await this.budgetsService.findOneAndValidateOwner(id, userId);
// Get current month spending
const spent = await this.calculateSpending(budget);
const remaining = Math.max(0, budget.amount - spent);
const percentage = Math.round((spent / budget.amount) * 100);
let status: string;
if (percentage >= 100) status = 'EXCEEDED';
else if (percentage >= 80) status = 'WARNING';
else status = 'OK';
return {
budgetId: budget.id,
amount: budget.amount,
spent,
remaining,
percentage,
status
};
}