import { Injectable, NotFoundException } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { User } from '../../entities/user.entity'; @Injectable() export class UsersService { constructor( @InjectRepository(User) private userRepository: Repository, ) {} async findById(id: string): Promise { const user = await this.userRepository.findOne({ where: { id }, select: ['id', 'email', 'username', 'totp_enabled', 'is_super_admin', 'created_at', 'last_login_at'], }); if (!user) { throw new NotFoundException('User not found'); } return user; } async findByEmail(email: string): Promise { return this.userRepository.findOne({ where: { email }, select: ['id', 'email', 'username', 'totp_enabled', 'is_super_admin', 'created_at', 'last_login_at'], }); } async findAll(): Promise { return this.userRepository.find({ select: ['id', 'email', 'username', 'totp_enabled', 'is_super_admin', 'created_at', 'last_login_at'], order: { created_at: 'DESC' }, }); } }