feat: add refresh token and global exception filter

This commit is contained in:
2026-05-09 09:00:25 +03:30
parent 06f659101d
commit 73f7af3146
32 changed files with 512 additions and 42 deletions
+31 -9
View File
@@ -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;