feat: add refresh token and global exception filter
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { Injectable, RequestTimeoutException } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
RequestTimeoutException,
|
||||
} from '@nestjs/common';
|
||||
import { Repository } from 'typeorm';
|
||||
import { User } from '../user.entity';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
@@ -13,14 +17,32 @@ export class UsersService {
|
||||
private readonly userRepository: Repository<User>,
|
||||
) {}
|
||||
|
||||
public async findOneById(id: number) {
|
||||
let user: User | null;
|
||||
try {
|
||||
user = await this.userRepository.findOneById(id);
|
||||
} catch (err) {
|
||||
throw new RequestTimeoutException('common.errors.requestTimeout', {
|
||||
cause: err,
|
||||
description: 'Error connecting to the database',
|
||||
});
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
throw new BadRequestException('users.errors.userNotExist');
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
public async findOneByPhone(phone: string) {
|
||||
try {
|
||||
return await this.userRepository.findOneBy({ phone });
|
||||
} 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' },
|
||||
);
|
||||
throw new RequestTimeoutException('common.errors.requestTimeout', {
|
||||
cause: err,
|
||||
description: 'Error connecting to the database',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +52,10 @@ export class UsersService {
|
||||
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' },
|
||||
);
|
||||
throw new RequestTimeoutException('common.errors.requestTimeout', {
|
||||
cause: err,
|
||||
description: 'Error connecting to the database',
|
||||
});
|
||||
}
|
||||
|
||||
return newUser;
|
||||
|
||||
Reference in New Issue
Block a user