import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { User } from './entities/user.entity';
import { Repository } from 'typeorm';
import { CreateUserDto } from './dto/create-user.dto';

@Injectable()
/**
 * Service responsible for handling user-related operations.
 */
export class UserService {
  constructor(@InjectRepository(User) private userRepository: Repository<User>) {}

  async findOne(email: string) {
    return await this.userRepository.findOneBy({ email });
  }

  async create(createUserDto: CreateUserDto) {
    await this.userRepository.insert(createUserDto);
  }

  async userExists(email: string): Promise<boolean> {
    const user = await this.userRepository.findOneBy({ email });
    if (user) return true;
    else return false;
  }
}
