feat: init project and add user module
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { Injectable, RequestTimeoutException } from '@nestjs/common';
|
||||
import { Repository } from 'typeorm';
|
||||
import { User } from '../user.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { CreateUserDTO } from '../dto/create-user.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(
|
||||
/**
|
||||
* Injecting User Repository
|
||||
*/
|
||||
@InjectRepository(User)
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
public async createOne(createUserDto: CreateUserDTO) {
|
||||
const newUser = this.userRepository.create(createUserDto);
|
||||
|
||||
try {
|
||||
await this.userRepository.save(newUser);
|
||||
} catch (err) {
|
||||
throw new RequestTimeoutException(
|
||||
'Unable to process your request at the moment. Please try again later.',
|
||||
{ cause: err, description: 'Error connecting to the database' },
|
||||
);
|
||||
}
|
||||
|
||||
return newUser;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user