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