import { hash } from 'bcrypt' ; import { Injectable } from '@nestjs/common' ; import { InjectRepository } from '@nestjs/typeorm' ; import { Repository , DeleteResult } from 'typeorm' ; import { User } from '../../entities/user.entity' ; import { CreateUserDto } from './dto/create-user.dto' ; @ Injectable ( ) export class UserService { constructor ( @ InjectRepository ( User ) private readonly repository ) { } public async findAll ( ) { return this . repository . find ( ) ; } public async findOne ( id ) { return this . repository . findOne ( id ) ; } public async findOneByEmail ( email ) { return this . repository . findOne ( { email } ) ; } public async create ( createUserDto ) { let { name , email , password } = createUserDto ; password = await hash ( password , 8 ) ; return this . repository . create ( { name , email , password } ) ; } public async save ( user ) { return this . repository . save ( user ) ; } public async delete ( id ) { return this . repository . delete ( id ) ; } }