11/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-argument */
2- import { Injectable , NotFoundException , ForbiddenException } from '@nestjs/common' ;
2+ import {
3+ Injectable ,
4+ NotFoundException ,
5+ ForbiddenException ,
6+ } from '@nestjs/common' ;
37import { InjectRepository } from '@nestjs/typeorm' ;
48import { Repository } from 'typeorm' ;
59import { CreateEvaluationDto } from './dto/create-evaluation.dto' ;
@@ -29,10 +33,14 @@ export class EvaluationService {
2933 async create ( createEvaluationDto : CreateEvaluationDto , user ?: User ) {
3034 // 1. Check Usage Limit (if user exists)
3135 if ( user ) {
32- const freshUser = await this . userRepository . findOne ( { where : { id : user . id } } ) ;
36+ const freshUser = await this . userRepository . findOne ( {
37+ where : { id : user . id } ,
38+ } ) ;
3339 if ( freshUser ) {
3440 const today = new Date ( ) . toDateString ( ) ;
35- const lastDate = freshUser . last_usage_date ? freshUser . last_usage_date . toDateString ( ) : null ;
41+ const lastDate = freshUser . last_usage_date
42+ ? freshUser . last_usage_date . toDateString ( )
43+ : null ;
3644
3745 // Reset if new day
3846 if ( lastDate !== today ) {
@@ -41,7 +49,9 @@ export class EvaluationService {
4149 }
4250
4351 if ( freshUser . usage_count >= freshUser . usage_limit ) {
44- throw new ForbiddenException ( 'Daily trial limit reached (10/10). Please upgrade or try again tomorrow.' ) ;
52+ throw new ForbiddenException (
53+ 'Daily trial limit reached (10/10). Please upgrade or try again tomorrow.' ,
54+ ) ;
4555 }
4656 }
4757 }
@@ -50,7 +60,9 @@ export class EvaluationService {
5060
5161 // Validation: Minimum Length
5262 if ( ! answer || answer . trim ( ) . length < 20 ) {
53- throw new ForbiddenException ( 'Answer is too short. Please write at least 20 characters to proceed.' ) ;
63+ throw new ForbiddenException (
64+ 'Answer is too short. Please write at least 20 characters to proceed.' ,
65+ ) ;
5466 }
5567
5668 // Use level/part from task or DTO if available, defaults provided
@@ -68,19 +80,33 @@ export class EvaluationService {
6880 // 2. Increment Usage Count & Update Date (Only on successful AI call)
6981 if ( user ) {
7082 // We perform a safe update that handles the reset implicitly by setting the value
71- const freshUser = await this . userRepository . findOne ( { where : { id : user . id } } ) ;
83+ const freshUser = await this . userRepository . findOne ( {
84+ where : { id : user . id } ,
85+ } ) ;
7286 if ( freshUser ) {
7387 const today = new Date ( ) ;
74- const lastDateStr = freshUser . last_usage_date ? freshUser . last_usage_date . toDateString ( ) : null ;
88+ const lastDateStr = freshUser . last_usage_date
89+ ? freshUser . last_usage_date . toDateString ( )
90+ : null ;
7591
7692 if ( lastDateStr !== today . toDateString ( ) ) {
7793 // First use of the day
78- await this . userRepository . update ( { id : user . id } , { usage_count : 1 , last_usage_date : today } ) ;
94+ await this . userRepository . update (
95+ { id : user . id } ,
96+ { usage_count : 1 , last_usage_date : today } ,
97+ ) ;
7998 } else {
8099 // Same day, just increment
81- await this . userRepository . increment ( { id : user . id } , 'usage_count' , 1 ) ;
100+ await this . userRepository . increment (
101+ { id : user . id } ,
102+ 'usage_count' ,
103+ 1 ,
104+ ) ;
82105 // Ensure date is current (though distinct days are handled above, keeping it fresh is fine)
83- await this . userRepository . update ( { id : user . id } , { last_usage_date : today } ) ;
106+ await this . userRepository . update (
107+ { id : user . id } ,
108+ { last_usage_date : today } ,
109+ ) ;
84110 }
85111 }
86112 }
0 commit comments