add auth and user handling
This commit is contained in:
parent
db057ce342
commit
1fce467571
19 changed files with 356 additions and 32 deletions
38
src/endpoints/UserPoint.ts
Normal file
38
src/endpoints/UserPoint.ts
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { Router } from "express";
|
||||
import { UserController } from "../controllers/UserController";
|
||||
import { CreateUserRequestDto } from "../dtos/CreateUserRequestDto";
|
||||
import { UserRepository } from "../repositories/UserRepository";
|
||||
import { UserDtoEntityMapper } from "../mappers/UserDtoEntityMapper";
|
||||
import {
|
||||
ValidationError,
|
||||
ConflictError,
|
||||
NotFoundError,
|
||||
InternalServerError,
|
||||
} from "../errors/httpErrors";
|
||||
|
||||
const router = Router();
|
||||
|
||||
// Inject repo + mapper here
|
||||
const userRepository = new UserRepository();
|
||||
const userMapper = new UserDtoEntityMapper();
|
||||
const userController = new UserController(userRepository, userMapper);
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
try {
|
||||
const requestDto: CreateUserRequestDto = req.body;
|
||||
const responseDto = await userController.createUser(requestDto);
|
||||
res.status(201).json(responseDto);
|
||||
} catch (err: any) {
|
||||
if (err instanceof ValidationError ||
|
||||
err instanceof ConflictError ||
|
||||
err instanceof NotFoundError) {
|
||||
res.status(err.statusCode).json({ error: err.message });
|
||||
} else {
|
||||
console.error("Unexpected error:", err);
|
||||
const internalError = new InternalServerError("Some unexpected error occurred!");
|
||||
res.status(internalError.statusCode).json({ error: internalError.message });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Loading…
Add table
Add a link
Reference in a new issue