Rename some API object and add update user to UserPoint. However, it seems to be broken somehow
This commit is contained in:
parent
81f1c3668b
commit
a9bd803112
12 changed files with 143 additions and 41 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import { Router } from "express";
|
||||
import { UserHandler } from "../handlers/UserHandler.js";
|
||||
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto.js";
|
||||
import { CreateUserRequest } from "../dtos/CreateUserRequest.js";
|
||||
import { UserRepository } from "../repositories/UserRepository.js";
|
||||
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
import {CreateUserResponse} from "../dtos/CreateUserResponse.js";
|
||||
import {UserDto} from "../dtos/UserDto.js";
|
||||
|
||||
/**
|
||||
* Handles all user related routes
|
||||
|
|
@ -11,24 +13,51 @@ import { asyncHandler } from "../utils/asyncHandler.js";
|
|||
const router = Router();
|
||||
|
||||
// Inject repo + mapper here
|
||||
const userRepository = new UserRepository();
|
||||
const userMapper = new UserDtoEntityMapper();
|
||||
const userController = new UserHandler(userRepository, userMapper);
|
||||
const handler
|
||||
= new UserHandler(new UserRepository(), new UserDtoEntityMapper());
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* Consumes CreateUserRequestDto
|
||||
* Consumes CreateUserRequest
|
||||
* Responds with UserDto
|
||||
*/
|
||||
router.post(
|
||||
"/",
|
||||
"/create",
|
||||
asyncHandler(async (req, res) => {
|
||||
const requestDto: CreateUserRequestDto = req.body;
|
||||
const responseDto = await userController.createUser(requestDto);
|
||||
res.status(201).json(responseDto);
|
||||
const request: CreateUserRequest = req.body;
|
||||
const user : UserDto = await handler.createUser(request);
|
||||
const response : CreateUserResponse = { userData: user };
|
||||
res.status(201).json(response);
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Update existing user
|
||||
* Consumes UserDto
|
||||
* Responds with UserDto
|
||||
* Does not allow for password change. Use change-password instead
|
||||
*/
|
||||
router.post(
|
||||
"/update",
|
||||
asyncHandler(async (req, res) => {
|
||||
const dto : UserDto = req.body;
|
||||
const response = await handler.updateUserData(dto);
|
||||
res.status(201).json(response);
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Update password of existing user
|
||||
* Consumes ChangeUserPasswordRequest
|
||||
* Responds with code 201 indicating success
|
||||
*/
|
||||
router.post(
|
||||
"/change-password",
|
||||
asyncHandler(async (req, res) => {
|
||||
throw Error("not implemented!");
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
* Get user data for current user
|
||||
* Responds with UserDto
|
||||
|
|
@ -39,7 +68,7 @@ router.get("/me",
|
|||
const id = req.currentUser?.id;
|
||||
if(id){
|
||||
// it breaks here because id is no longer a uuid
|
||||
const responseDto = await userController.getUserById(id);
|
||||
const responseDto = await handler.getUserById(id);
|
||||
res.status(201).json(responseDto);
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue