From 39f349b2480691bdbc4965ababfddb6274d20856 Mon Sep 17 00:00:00 2001 From: Ibrahim Suleiman Date: Sun, 12 Apr 2026 13:09:04 +0100 Subject: [PATCH] chore: update user entity and add check to user service --- src/user/entities/user.entity.ts | 5 ++++- src/user/user.service.ts | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/user/entities/user.entity.ts b/src/user/entities/user.entity.ts index 2bfdb3c..bff6ab5 100644 --- a/src/user/entities/user.entity.ts +++ b/src/user/entities/user.entity.ts @@ -19,7 +19,7 @@ export class User { @Column({ nullable: true, default: null }) other_names: string; - @Column() + @Column({ unique: true }) email: string; @Column() @@ -28,6 +28,9 @@ export class User { @Column({ default: 1 }) auth_token_version: number; + @Column({ default: false }) + has_verified_email: boolean; + @CreateDateColumn() created_at: Date; } diff --git a/src/user/user.service.ts b/src/user/user.service.ts index 730eaaf..bdd6682 100644 --- a/src/user/user.service.ts +++ b/src/user/user.service.ts @@ -1,4 +1,8 @@ -import { BadRequestException, Injectable } from '@nestjs/common'; +import { + BadRequestException, + Injectable, + UnprocessableEntityException, +} from '@nestjs/common'; import { CreateUserDto } from './dto/create-user.dto'; import { InjectRepository } from '@nestjs/typeorm'; import { User } from './entities/user.entity'; @@ -27,7 +31,13 @@ export class UserService { user.email = data.email; user.password_hash = await hashString(data.password); - await this.userRepository.save(user); + const saved = await this.userRepository.save(user); + + if (!saved) { + throw new UnprocessableEntityException( + 'failed to add user. please try again.', + ); + } return { message: 'success', @@ -38,5 +48,4 @@ export class UserService { }, }; } - }