import { Inject , Injectable , NotFoundException } from '@nestjs/common' ; import { OrderEnum } from '../../../CommonsModule/enum/order.enum' ; import { CourseTakenRepository } from '../../repository/course.taken.repository' ; import { CourseTaken } from '../../entity/course-taken.entity' ; import { getCoursesByFinished } from '../../../DashboardModule/interfaces/getCoursesByFinished' ; import { PublisherService } from '../../../GameficationModule/service/publisher.service' ; @ Injectable ( ) export class CourseTakenService { @ Inject ( PublisherService ) private readonly publisherService : PublisherService ; constructor ( private readonly repository ) { } public async getActiveUsersQuantity ( ) { return this . repository . getActiveUsersQuantity ( ) ; } public async getCertificateQuantity ( ) { return this . repository . getCertificateQuantity ( ) ; } public async getUsersWithTakenCourses ( ) { return this . repository . getUsersWithTakenCourses ( ) ; } public async getUsersWithCompletedCourses ( ) { return this . repository . getUsersWithCompletedCourses ( ) ; } public async getUsersWithCompletedAndTakenCourses ( ) { return this . repository . getUsersWithCompletedAndTakenCourses ( ) ; } public async getCoursesByFinished ( order , limit ) { return this . repository . getDistinctCourses ( order , limit ) ; } public async findByUserIdAndCourseId ( userId , courseId ) { const courseTaken = this . repository . findByUserIdAndCourseId ( userId , courseId ) ; if ( ! courseTaken ) { throw new NotFoundException ( 'Course not taken by user' ) ; } return courseTaken ; } }