Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions apps/backend/src/donations/donations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
UseInterceptors,
Req,
UnauthorizedException,
BadRequestException,
} from '@nestjs/common';
import {
ApiTags,
Expand Down Expand Up @@ -316,6 +317,20 @@ export class DonationsController {
type: Number,
description: 'maximum donation amount',
})
@ApiQuery({
name: 'startDate',
required: false,
type: String,
description: 'filter by start date (YYYY-MM-DD format)',
example: '2026-01-01',
})
@ApiQuery({
name: 'endDate',
required: false,
type: String,
description: 'filter by end date (YYYY-MM-DD format)',
example: '2026-12-31',
})
@ApiResponse({
status: 200,
description: 'paginated donation list',
Expand Down Expand Up @@ -351,6 +366,8 @@ export class DonationsController {
minAmount?: number,
@Query('maxAmount', new ParseIntPipe({ optional: true }))
maxAmount?: number,
@Query('startDate') startDateStr?: string,
@Query('endDate') endDateStr?: string,
): Promise<{
rows: DonationResponseDto[];
total: number;
Expand All @@ -365,13 +382,36 @@ export class DonationsController {
throw new UnauthorizedException('Admin access required');
}

let startDate: Date | undefined;
let endDate: Date | undefined;

if (startDateStr) {
startDate = new Date(startDateStr);
if (isNaN(startDate.getTime())) {
throw new BadRequestException(
'Invalid startDate format. Use YYYY-MM-DD',
);
}
}

if (endDateStr) {
endDate = new Date(endDateStr);
// Add one day to endDate to include the entire end date
endDate.setDate(endDate.getDate() + 1);
if (isNaN(endDate.getTime())) {
throw new BadRequestException('Invalid endDate format. Use YYYY-MM-DD');
Comment thread
ItsEricSun marked this conversation as resolved.
}
}

const filters: PaginationFilters = {
donationType,
status,
isAnonymous,
recurringInterval,
minAmount,
maxAmount,
startDate,
endDate,
};

const result = await this.donationsRepository.findPaginated(
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class ApiClient {
this.handleAxiosError(err, 'Failed to reset password');
}
}

public async getActiveGoalSummary(): Promise<ActiveGoalResponse> {
try {
const res = await this.axiosInstance.get('/api/donations/goal/active');
Expand Down Expand Up @@ -183,6 +183,8 @@ export class ApiClient {
perPage?: number;
donationType?: 'one_time' | 'recurring';
status?: 'pending' | 'succeeded' | 'failed' | 'cancelled';
startDate?: string;
endDate?: string;
}): Promise<{
rows: Array<{
id: number;
Expand Down
Loading
Loading