diff --git a/src/card/services/card.service.ts b/src/card/services/card.service.ts index b9df3fd..23c6f6f 100644 --- a/src/card/services/card.service.ts +++ b/src/card/services/card.service.ts @@ -163,8 +163,8 @@ export class CardService { return finalAmount.toNumber(); } - getWeeklySummary(juniorId: string) { - return this.transactionService.getWeeklySummary(juniorId); + getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) { + return this.transactionService.getWeeklySummary(juniorId, startDate, endDate); } fundIban(iban: string, amount: number) { diff --git a/src/card/services/transaction.service.ts b/src/card/services/transaction.service.ts index 1ac0134..39ca853 100644 --- a/src/card/services/transaction.service.ts +++ b/src/card/services/transaction.service.ts @@ -84,15 +84,28 @@ export class TransactionService { return existingTransaction; } - async getWeeklySummary(juniorId: string) { - const endOfWeek = moment().toDate(); - const startOfWeek = moment().subtract(1, 'week').toDate(); + async getWeeklySummary(juniorId: string, startDate?: Date, endDate?: Date) { + let startOfWeek: Date; + 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( juniorId, startOfWeek, endOfWeek, ); + const summary = { startOfWeek: startOfWeek, endOfWeek: endOfWeek, diff --git a/src/junior/controllers/junior.controller.ts b/src/junior/controllers/junior.controller.ts index 0ffd532..d04eded 100644 --- a/src/junior/controllers/junior.controller.ts +++ b/src/junior/controllers/junior.controller.ts @@ -151,11 +151,17 @@ export class JuniorController { @UseGuards(RolesGuard) @AllowedRoles(Roles.GUARDIAN) @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( @Param('juniorId', CustomParseUUIDPipe) juniorId: string, @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); } diff --git a/src/junior/services/junior.service.ts b/src/junior/services/junior.service.ts index 9f3647c..2a799c4 100644 --- a/src/junior/services/junior.service.ts +++ b/src/junior/services/junior.service.ts @@ -212,7 +212,7 @@ export class JuniorService { 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); if (!doesBelong) { @@ -221,7 +221,7 @@ export class JuniorService { } 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 { diff --git a/src/user/services/user.service.ts b/src/user/services/user.service.ts index 188accb..73e2e58 100644 --- a/src/user/services/user.service.ts +++ b/src/user/services/user.service.ts @@ -226,7 +226,15 @@ export class UserService { if (userWithEmail) { if (userWithEmail.id === userId) { - return; + this.logger.log(`Generating OTP for current email ${email} for user ${userId}`); + await this.userRepository.update(userId, { isEmailVerified: false }); + + return this.otpService.generateAndSendOtp({ + userId, + recipient: email, + otpType: OtpType.EMAIL, + scope: OtpScope.VERIFY_EMAIL, + }); } this.logger.error(`Email ${email} is already taken by another user`);