Skip to content

Instantly share code, notes, and snippets.

@Mr-Malomz
Created September 1, 2020 21:34
Show Gist options
  • Save Mr-Malomz/86a793a74f4e8ddc3e80b1db28165b8c to your computer and use it in GitHub Desktop.
Save Mr-Malomz/86a793a74f4e8ddc3e80b1db28165b8c to your computer and use it in GitHub Desktop.
signUp User
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