Fix build and implement user/all correctly

This commit is contained in:
araemer 2025-11-18 20:26:28 +01:00
parent a9bd803112
commit 555dacfaf5
17 changed files with 170 additions and 48 deletions

View file

@ -6,11 +6,19 @@ import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper.js";
import { asyncHandler } from "../utils/asyncHandler.js";
import {CreateUserResponse} from "../dtos/CreateUserResponse.js";
import {UserDto} from "../dtos/UserDto.js";
import {requireAdmin} from "../middleware/authorizationMiddleware.js";
import {UserListResponse} from "../dtos/UserListResponse.js";
import {HttpStatusCode} from "../apiHelpers/HttpStatusCodes.js";
export const userBasicRoute = "/user";
/**
* Handles all user related routes
*/
const router = Router();
router.use((req, res, next) => {
console.log(`Incoming request: ${req.method} ${req.path}`);
next();
});
// Inject repo + mapper here
const handler
@ -42,9 +50,9 @@ router.post(
asyncHandler(async (req, res) => {
const dto : UserDto = req.body;
const response = await handler.updateUserData(dto);
res.status(201).json(response);
res.status(HttpStatusCode.CREATED).json(response);
})
)
);
/**
* Update password of existing user
@ -56,7 +64,22 @@ router.post(
asyncHandler(async (req, res) => {
throw Error("not implemented!");
})
)
);
/**
* Get all users (admin only)
* Responds with array of UserDto
*/
router.get(
"/all",
//requireAdmin,
asyncHandler(async (req, res) => {
const id = req.currentUser?.id;
const users = await handler.getAllUsers();
const response : UserListResponse = {valueList: users}
res.status(HttpStatusCode.OK).json(response);
})
);
/**
* Get user data for current user
@ -67,9 +90,8 @@ router.get("/me",
const id = req.currentUser?.id;
if(id){
// it breaks here because id is no longer a uuid
const responseDto = await handler.getUserById(id);
res.status(201).json(responseDto);
res.status(HttpStatusCode.OK).json(responseDto);
}
})
);