running now

This commit is contained in:
Anika Raemer 2025-09-22 20:17:46 +02:00
parent 85cd083750
commit c17bb05f0a
25 changed files with 156 additions and 114 deletions

View file

@ -1,10 +1,9 @@
import { ValidationError, ConflictError } from "../errors/httpErrors";
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto";
import { UserDto } from "../dtos/UserDto";
import { encrypt } from "../utils/encryptionUtils";
import { UserRepository } from "../repositories/UserRepository";
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper";
import { isNeitherNullNorEmpty } from "../utils/stringUtils";
import { ValidationError, ConflictError } from "../errors/httpErrors.js";
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto.js";
import { UserDto } from "../dtos/UserDto.js";
import { encrypt } from "../utils/encryptionUtils.js";
import { UserRepository } from "../repositories/UserRepository.js";
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper.js";
export class UserController {
constructor(
@ -14,23 +13,30 @@ export class UserController {
async createUser(dto: CreateUserRequestDto): Promise<UserDto> {
// check mandatory fields
if (!isNeitherNullNorEmpty(dto.userData.email)) {
if(!dto.userData){
throw new ValidationError("User data is required")
}
const email = dto.userData.email;
if (!email || (email && email.length == 0)) {
throw new ValidationError("Email is required");
}
if (!isNeitherNullNorEmpty(dto.userData.userName)) {
throw new ValidationError("Username is required");
}
if(!isNeitherNullNorEmpty(dto.password){
const password = dto.password;
if(!password || (password && password.length == 0)){
throw new ValidationError("Password is required");
}
// user name must be uniqu
const existingUser = await this.userRepository.findByUserName(dto.userData.email);
const userName = dto.userData.userName;
if (!userName|| (userName && userName.length == 0)){
throw new ValidationError("Username is required");
}
// user name must be unique
const existingUser = await this.userRepository.findByUserName(userName);
if (existingUser) {
throw new ConflictError("User with this user name already exists");
}
const userEntity = this.mapper.toEntity(dto.userData);
userEntity.password = await encrypt.encryptpass(dto.password);
userEntity.password = await encrypt.encryptpass(password);
const savedUser = await this.userRepository.create(userEntity);