This commit is contained in:
@@ -20,10 +20,6 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||
const startDate = new Date();
|
||||
startDate.setMonth(startDate.getMonth() - monthsBack);
|
||||
|
||||
// First, let's get all payments and see what we have
|
||||
console.log('Searching for payments for user:', session.user.nickname);
|
||||
console.log('Date range:', startDate.toISOString(), 'to', endDate.toISOString());
|
||||
|
||||
const totalPayments = await Payment.countDocuments();
|
||||
const paymentsInRange = await Payment.countDocuments({
|
||||
date: {
|
||||
@@ -36,13 +32,8 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||
$gte: startDate,
|
||||
$lte: endDate
|
||||
},
|
||||
category: { $ne: 'settlement' },
|
||||
$or: [
|
||||
{ paidBy: session.user.nickname },
|
||||
{ createdBy: session.user.nickname }
|
||||
]
|
||||
category: { $ne: 'settlement' }
|
||||
});
|
||||
console.log('Total payments:', totalPayments, 'In date range:', paymentsInRange, 'User expenses:', expensePayments);
|
||||
|
||||
// Aggregate payments by month and category
|
||||
const pipeline = [
|
||||
@@ -54,11 +45,6 @@ export const GET: RequestHandler = async ({ url, locals }) => {
|
||||
},
|
||||
// Exclude settlements - only show actual expenses
|
||||
category: { $ne: 'settlement' },
|
||||
// Only include payments where current user is involved
|
||||
$or: [
|
||||
{ paidBy: session.user.nickname },
|
||||
{ createdBy: session.user.nickname }
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@@ -66,13 +66,11 @@
|
||||
async function fetchMonthlyExpenses() {
|
||||
try {
|
||||
expensesLoading = true;
|
||||
console.log('Fetching monthly expenses...');
|
||||
const response = await fetch('/api/cospend/monthly-expenses');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch monthly expenses');
|
||||
}
|
||||
monthlyExpensesData = await response.json();
|
||||
console.log('Monthly expenses data:', monthlyExpensesData);
|
||||
} catch (err) {
|
||||
console.error('Error fetching monthly expenses:', err);
|
||||
// Don't show this error in the main error state
|
||||
|
Reference in New Issue
Block a user