import { Injectable, NotFoundException } from '@nestjs/common'; import { ReviewRepository } from './review.repository'; import { SubmitReviewDto } from './dto/submit-review.dto'; @Injectable() export class ReviewService { constructor(private readonly reviewRepository: ReviewRepository) {} async getDueCards(userId: string) { return this.reviewRepository.findDueCards(userId); } async submitReview(userId: string, id: string, dto: SubmitReviewDto) { const card = await this.reviewRepository.findById(id); if (!card) throw new NotFoundException(`Review card ${id} not found`); const log = await this.reviewRepository.insertLog({ userId, reviewCardId: id, rating: dto.rating, responseText: dto.responseText, }); await this.reviewRepository.updateCard(id, { status: 'reviewed', nextReviewAt: new Date(Date.now() + 86400000), }); return log; } }