File size: 1,059 Bytes
e67d35c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Injectable, Logger } from '@nestjs/common';
import { Cron, CronExpression } from '@nestjs/schedule';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { CourseAnalytics } from '../entities/course-analytics.entity';
import { StudentProgress } from '../entities/student-progress.entity';

@Injectable()
export class AnalyticsCronService {
  private readonly logger = new Logger(AnalyticsCronService.name);

  constructor(
    @InjectRepository(CourseAnalytics)
    private courseAnalyticsRepo: Repository<CourseAnalytics>,
    @InjectRepository(StudentProgress)
    private studentProgressRepo: Repository<StudentProgress>,
  ) {}

  @Cron(CronExpression.EVERY_DAY_AT_2AM)
  async handleDailyAnalyticsSnapshot() {
    this.logger.log('Running daily analytics snapshot...');
    // Placeholder: aggregate course_analytics data
    // In production, this would query enrollments, grades, attendance
    // and update course_analytics records
    this.logger.log('Daily analytics snapshot completed');
  }
}