All files / learning learning.controller.ts

0% Statements 0/38
0% Branches 0/39
0% Functions 0/9
0% Lines 0/32

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107                                                                                                                                                                                                                     
import { Controller, Get, Post, Body, Param, Query, BadRequestException } from '@nestjs/common';
import { LearningService } from './learning.service';
 
@Controller('api/v1/learning')
export class LearningController {
  constructor(private readonly learningService: LearningService) {}
 
  @Post('enrol')
  async enrol(
    @Body('tenantId') tenantId: string,
    @Body('employeeId') employeeId: string,
    @Body('courseId') courseId: string,
    @Body('source') source?: string
  ) {
    if (!tenantId || !employeeId || !courseId) {
      throw new BadRequestException('Required fields missing');
    }
    return this.learningService.enrolInCourse(tenantId, employeeId, courseId, source);
  }
 
  @Post('progress/sync')
  async syncProgress(
    @Body('tenantId') tenantId: string,
    @Body('employeeId') employeeId: string,
    @Body('courseId') courseId: string,
    @Body('lessonId') lessonId: string,
    @Body('timeSpentSeconds') timeSpentSeconds: number,
    @Body('playbackPosition') playbackPosition?: number
  ) {
    if (!tenantId || !employeeId || !courseId || !lessonId) {
      throw new BadRequestException('Required fields missing');
    }
    return this.learningService.recordLessonProgress(
      tenantId,
      employeeId,
      courseId,
      lessonId,
      timeSpentSeconds,
      playbackPosition
    );
  }
 
  @Post('assessment/submit')
  async submitAssessment(
    @Body('tenantId') tenantId: string,
    @Body('employeeId') employeeId: string,
    @Body('assessmentId') assessmentId: string,
    @Body('answers') answers: Record<string, number[]>
  ) {
    if (!tenantId || !employeeId || !assessmentId || !answers) {
      throw new BadRequestException('Required fields missing');
    }
    return this.learningService.gradeAssessmentAttempt(tenantId, employeeId, assessmentId, answers);
  }
 
  @Get('secure-url')
  async getSecureUrl(
    @Query('tenantId') tenantId: string,
    @Query('fileKey') fileKey: string
  ) {
    if (!tenantId || !fileKey) {
      throw new BadRequestException('Required query parameters missing');
    }
    const url = await this.learningService.getSecureContentUrl(tenantId, fileKey);
    return { url };
  }
}
 
@Controller('api/v1/mobile/learning')
export class MobileLearningController {
  constructor(private readonly learningService: LearningService) {}
 
  @Get('dashboard')
  async getDashboard(@Query('tenantId') tenantId: string, @Query('employeeId') employeeId: string) {
    return {
      activeEnrolments: 3,
      completedCourses: 5,
      totalPoints: 450,
      certificatesCount: 2,
      recommendations: [
        { courseId: 'mock-1', title: 'Kubernetes Production Deployments', difficulty: 'advanced' },
        { courseId: 'mock-2', title: 'NestJS Microservices Design Patterns', difficulty: 'intermediate' }
      ]
    };
  }
}
 
@Controller('api/v1/public/learning')
export class PublicLearningController {
  constructor(private readonly learningService: LearningService) {}
 
  @Get('verify/:token')
  async verifyCertificate(@Param('token') token: string) {
    const cert = await this.learningService.verifyPublicCertificate(token);
    if (!cert) {
      return { verified: false, message: 'Invalid or revoked certificate verification token' };
    }
    return {
      verified: true,
      certificateName: cert.certificateName,
      issuedAt: cert.issuedAt,
      expiresAt: cert.expiresAt,
      status: cert.status
    };
  }
}