import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ModuleEntity } from './entities/modules.entity';

@Injectable()
export class ModulesService {
  constructor(
    @InjectRepository(ModuleEntity)
    private readonly moduleRepository: Repository<ModuleEntity>,
  ) {}

  async findAll(): Promise<ModuleEntity[]> {
    try {
      return await this.moduleRepository.find();
    } catch (error) {
      throw new Error('Error fetching modules: ' + error.message);
    }
  }
}
