Created
September 1, 2020 21:34
-
-
Save Mr-Malomz/86a793a74f4e8ddc3e80b1db28165b8c to your computer and use it in GitHub Desktop.
signUp User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Repository, EntityRepository } from 'typeorm'; | |
import { User } from './user.entity'; | |
import { AuthSignUpDto } from './dto/auth-signup.dto'; | |
import { | |
ConflictException, | |
InternalServerErrorException, | |
} from '@nestjs/common'; | |
@EntityRepository(User) | |
export class UserRepository extends Repository<User> { | |
async signUp(authSignUpDto: AuthSignUpDto): Promise<string> { | |
const { email, password, firstname, lastname } = authSignUpDto; | |
const user = new User(); | |
user.email = email; | |
user.password = password; | |
user.firstname = firstname; | |
user.lastname = lastname; | |
try { | |
await user.save(); | |
return 'User created successfully'; | |
} catch (error) { | |
if (error.code === '23505') { | |
throw new ConflictException('Email already exists'); | |
} else { | |
throw new InternalServerErrorException(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment