import { Injectable } from '@nestjs/common' ; import { CreateUserDto } from './dto/create-user.dto' ; import { UpdateUserDto } from './dto/update-user.dto' ; import { User } from './entities/user.entity' ; import { UserRepository } from '../db/repositories/UserRepository' ; @ Injectable ( ) export class UserService { constructor ( private userRepository ) { } async create ( createUserDto ) { const { username , password , email } = createUserDto ; const user = new User ( ) ; user . username = username ; user . password = password ; user . email = email ; user . is_admin = 1 ; return this . userRepository . save ( user ) ; } async findAll ( ) { return this . userRepository . find ( ) ; } async findOne ( id ) { return this . userRepository . findOne ( id ) ; } async findByUsername ( username ) { return this . userRepository . findOne ( { where : { username } , } ) ; } async update ( id , updateUserDto ) { const { username , password , email } = updateUserDto ; return this . userRepository . update ( { id } , { username , password , email } ) ; } async remove ( id ) { return this . userRepository . delete ( { id , } ) ; } async checkAdmin ( id ) { return this . userRepository . findOne ( { where : { id , is_admin : 1 } , } ) ; } }