import { Injectable , NotAcceptableException } from '@nestjs/common' ; import { InjectRepository } from '@nestjs/typeorm' ; import { Repository } from 'typeorm' ; import { User , UserFillableFields } from './user.entity' ; @ Injectable ( ) export class UsersService { constructor ( @ InjectRepository ( User ) private readonly userRepository ) { } async get ( id ) { return this . userRepository . findOne ( { id } ) ; } async getByEmail ( email ) { return await this . userRepository . findOne ( { email } ) ; } async create ( payload ) { const user = await this . getByEmail ( payload . email ) ; if ( user ) { throw new NotAcceptableException ( 'User with provided email already created.' ) ; } return await this . userRepository . save ( payload ) ; } }