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