import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { UserLevelProgress } from '../entities/user-level-progress.entity'; import { IUserLevelProgressRepository } from './user-level-progress.repository.interface'; @Injectable() export class UserLevelProgressRepository implements IUserLevelProgressRepository { constructor( @InjectRepository(UserLevelProgress) private readonly repository: Repository, ) {} async findByUserId(userId: string): Promise { return this.repository.find({ where: { userId } }); } async countByUserId(userId: string): Promise { return this.repository.count({ where: { userId } }); } async findByUserAndLevel( userId: string, levelId: string, ): Promise { return this.repository.findOne({ where: { userId, levelId } }); } create(data: Partial): UserLevelProgress { return this.repository.create(data); } async save(progress: UserLevelProgress): Promise { return this.repository.save(progress); } }