Skip to content

Commit

Permalink
FIX : create user should not return user
Browse files Browse the repository at this point in the history
  • Loading branch information
juliecoust committed Jul 9, 2024
1 parent 4062018 commit eef2f7f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/domain/interfaces/use-cases/user/create-user.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UserRequestCreationModel, UserResponseModel } from "../../../entities/user";
import { UserRequestCreationModel } from "../../../entities/user";
export interface CreateUserUseCase {
execute(user: UserRequestCreationModel): Promise<UserResponseModel>;
execute(user: UserRequestCreationModel): Promise<void>;
}

10 changes: 5 additions & 5 deletions src/domain/use-cases/user/create-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class CreateUser implements CreateUserUseCase {
this.userRepository = userRepository
this.mailer = mailer
}
async execute(user: UserRequestCreationModel): Promise<UserResponseModel> {
async execute(user: UserRequestCreationModel): Promise<void> {
// Retrieve a pre-existing user by email
const preexistentUser = await this.userRepository.getUser({ email: user.email });

Expand Down Expand Up @@ -45,9 +45,9 @@ export class CreateUser implements CreateUserUseCase {
await this.generateTokenAndSendEmail(updatedUser)

// Remove the confirmation code from the user object before sending it
const publicUser = this.userRepository.toPublicUser(updatedUser)
// const publicUser = this.userRepository.toPublicUser(updatedUser)

return publicUser;
// return publicUser;
} else {
// If the user exists and has already validated their email
throw new Error("Valid user already exists");
Expand All @@ -63,8 +63,8 @@ export class CreateUser implements CreateUserUseCase {

this.generateTokenAndSendEmail(createdUser)
// Remove the confirmation code from the user object before sending it
const publicUser = this.userRepository.toPublicUser(createdUser)
return publicUser;
//const publicUser = this.userRepository.toPublicUser(createdUser)
//return publicUser;
}

private async generateTokenAndSendEmail(user: UserResponseModel): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/presentation/routers/user-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default function UsersRouter(

router.post('/', middlewareUserValidation.rulesUserRequestCreationModel, async (req: Request, res: Response) => {
try {
const created_user = await createUserUseCase.execute(req.body)
res.status(201).send(created_user)
await createUserUseCase.execute(req.body)
res.status(201).send("User created")
} catch (err) {
console.log(err)
if (err.message === "Valid user already exist") res.status(403).send({ errors: ["Cannot create user"] })
Expand Down

0 comments on commit eef2f7f

Please sign in to comment.