mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 00:24:54 +00:00
Enhance weekly summary functionality to accept optional date range parameters in CardService, TransactionService, JuniorService, and JuniorController. Update API documentation to reflect new query parameters for start and end dates.
This commit is contained in:
@ -163,8 +163,8 @@ export class CardService {
|
|||||||
return finalAmount.toNumber();
|
return finalAmount.toNumber();
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeeklySummary(juniorId: string) {
|
getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) {
|
||||||
return this.transactionService.getWeeklySummary(juniorId);
|
return this.transactionService.getWeeklySummary(juniorId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
fundIban(iban: string, amount: number) {
|
fundIban(iban: string, amount: number) {
|
||||||
|
|||||||
@ -84,15 +84,28 @@ export class TransactionService {
|
|||||||
return existingTransaction;
|
return existingTransaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWeeklySummary(juniorId: string) {
|
async getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) {
|
||||||
const endOfWeek = moment().toDate();
|
let startOfWeek: Date;
|
||||||
const startOfWeek = moment().subtract(1, 'week').toDate();
|
let endOfWeek: Date;
|
||||||
|
|
||||||
|
if (startDate && endDate) {
|
||||||
|
startOfWeek = startDate;
|
||||||
|
endOfWeek = endDate;
|
||||||
|
} else {
|
||||||
|
const now = moment();
|
||||||
|
const dayOfWeek = now.day();
|
||||||
|
|
||||||
|
startOfWeek = moment().subtract(dayOfWeek, 'days').startOf('day').toDate();
|
||||||
|
|
||||||
|
endOfWeek = moment().add(6 - dayOfWeek, 'days').endOf('day').toDate();
|
||||||
|
}
|
||||||
|
|
||||||
const transactions = await this.transactionRepository.getTransactionsForCardWithinDateRange(
|
const transactions = await this.transactionRepository.getTransactionsForCardWithinDateRange(
|
||||||
juniorId,
|
juniorId,
|
||||||
startOfWeek,
|
startOfWeek,
|
||||||
endOfWeek,
|
endOfWeek,
|
||||||
);
|
);
|
||||||
|
|
||||||
const summary = {
|
const summary = {
|
||||||
startOfWeek: startOfWeek,
|
startOfWeek: startOfWeek,
|
||||||
endOfWeek: endOfWeek,
|
endOfWeek: endOfWeek,
|
||||||
|
|||||||
@ -151,11 +151,17 @@ export class JuniorController {
|
|||||||
@UseGuards(RolesGuard)
|
@UseGuards(RolesGuard)
|
||||||
@AllowedRoles(Roles.GUARDIAN)
|
@AllowedRoles(Roles.GUARDIAN)
|
||||||
@ApiDataResponse(WeeklySummaryResponseDto)
|
@ApiDataResponse(WeeklySummaryResponseDto)
|
||||||
|
@ApiQuery({ name: 'startUtc', required: false, type: String, example: '2025-10-20T00:00:00.000Z', description: 'Start date (defaults to start of current week)' })
|
||||||
|
@ApiQuery({ name: 'endUtc', required: false, type: String, example: '2025-10-26T23:59:59.999Z', description: 'End date (defaults to end of current week)' })
|
||||||
async getWeeklySummary(
|
async getWeeklySummary(
|
||||||
@Param('juniorId', CustomParseUUIDPipe) juniorId: string,
|
@Param('juniorId', CustomParseUUIDPipe) juniorId: string,
|
||||||
@AuthenticatedUser() user: IJwtPayload,
|
@AuthenticatedUser() user: IJwtPayload,
|
||||||
|
@Query('startUtc') startUtc?: string,
|
||||||
|
@Query('endUtc') endUtc?: string,
|
||||||
) {
|
) {
|
||||||
const summary = await this.juniorService.getWeeklySummary(juniorId, user.sub);
|
const startDate = startUtc ? new Date(startUtc) : undefined;
|
||||||
|
const endDate = endUtc ? new Date(endUtc) : undefined;
|
||||||
|
const summary = await this.juniorService.getWeeklySummary(juniorId, user.sub, startDate, endDate);
|
||||||
return ResponseFactory.data(summary);
|
return ResponseFactory.data(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -212,7 +212,7 @@ export class JuniorService {
|
|||||||
this.logger.log(`Junior ${juniorId} deleted successfully`);
|
this.logger.log(`Junior ${juniorId} deleted successfully`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getWeeklySummary(juniorId: string, guardianId: string) {
|
async getWeeklySummary(juniorId: string, guardianId: string, startDate?: Date, endDate?: Date) {
|
||||||
const doesBelong = await this.doesJuniorBelongToGuardian(guardianId, juniorId);
|
const doesBelong = await this.doesJuniorBelongToGuardian(guardianId, juniorId);
|
||||||
|
|
||||||
if (!doesBelong) {
|
if (!doesBelong) {
|
||||||
@ -221,7 +221,7 @@ export class JuniorService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.logger.log(`Getting weekly summary for junior ${juniorId}`);
|
this.logger.log(`Getting weekly summary for junior ${juniorId}`);
|
||||||
return this.cardService.getWeeklySummary(juniorId);
|
return this.cardService.getWeeklySummary(juniorId, startDate, endDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getJuniorHome(juniorId: string, userId: string, size: number): Promise<JuniorHomeResponseDto> {
|
async getJuniorHome(juniorId: string, userId: string, size: number): Promise<JuniorHomeResponseDto> {
|
||||||
|
|||||||
Reference in New Issue
Block a user