25 lines
920 B
TypeScript
25 lines
920 B
TypeScript
|
|
import { Injectable, NotFoundException, OnModuleInit } from '@nestjs/common';
|
||
|
|
import { ReviewRepository, ReviewCard, ReviewLog } from './review.repository';
|
||
|
|
import { SubmitReviewDto } from './dto/submit-review.dto';
|
||
|
|
|
||
|
|
@Injectable()
|
||
|
|
export class ReviewService implements OnModuleInit {
|
||
|
|
constructor(private readonly reviewRepository: ReviewRepository) {}
|
||
|
|
|
||
|
|
onModuleInit() {}
|
||
|
|
|
||
|
|
async getDueCards(): Promise<ReviewCard[]> {
|
||
|
|
return this.reviewRepository.findDueCards();
|
||
|
|
}
|
||
|
|
|
||
|
|
async submitReview(id: string, dto: SubmitReviewDto): Promise<ReviewLog> {
|
||
|
|
const card = await this.reviewRepository.findById(id);
|
||
|
|
if (!card) throw new NotFoundException(`Review card ${id} not found`);
|
||
|
|
const log = await this.reviewRepository.insertLog({
|
||
|
|
cardId: id, rating: dto.rating, responseText: dto.responseText,
|
||
|
|
});
|
||
|
|
await this.reviewRepository.updateCard(id, { reviewedAt: new Date() });
|
||
|
|
return log;
|
||
|
|
}
|
||
|
|
}
|