refactor delete user endpoint

This commit is contained in:
faris Aljohari
2024-09-30 02:10:41 -05:00
parent a3cce2b21c
commit 2b9788eff7
4 changed files with 26 additions and 28 deletions
+11
View File
@@ -14,6 +14,7 @@ import { UserRepository } from '@app/common/modules/user/repositories';
import { RegionRepository } from '@app/common/modules/region/repositories';
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
import { UserEntity } from '@app/common/modules/user/entities';
@Injectable()
export class UserService {
@@ -237,4 +238,14 @@ export class UserService {
);
}
}
async findOneById(id: string): Promise<UserEntity> {
return await this.userRepository.findOne({ where: { uuid: id } });
}
async deleteUser(uuid: string) {
const user = await this.findOneById(uuid);
if (!user) {
throw new BadRequestException('User not found');
}
return await this.userRepository.update({ uuid }, { isActive: false });
}
}